formers / former Goto Github PK
View Code? Open in Web Editor NEWA powerful form builder, for Laravel and other frameworks (stand-alone too)
Home Page: https://formers.github.io/former/
A powerful form builder, for Laravel and other frameworks (stand-alone too)
Home Page: https://formers.github.io/former/
The check function for check box works a bit weird in my opinion. I'd like to do pass a test to decide whether it should be checked a not. But to do this I need to pass an array with the name of the check box and state. Wouldn't it be easier to simply be able to pass a true or false to decide whether it should be checked when it's a single item?
When passing an array you can set individual states of checkboxes, but for single items it's always assumed you want to set checked to true.
I'd like to be able to the following: Former::checkbox('blabla')->check(resultoftest());
Current:
/**
* Check a specific item
*
* @param string $checked The checkable to check, or an array of checked items
*/
public function check($checked = null)
{
// If we're setting all the checked items at once
if(is_array($checked)) {
return $this->checked = $checked;
}
// Else we're setting a single item
if(is_null($checked)) $checked = $this->name;
$this->checked[$checked] = true;
}
Possible change:
/**
* Check a specific item
*
* @param string $checked The checkable to check, or an array of checked items
*/
public function check($checked = true) {
// If we're setting all the checked items at once
if (is_array($checked)) {
return $this->checked = $checked;
}
// Only setting a single item
$this->checked[$this->name] = (bool) $checked;
return (bool) $checked;
}
Hi
Sorry if this is a real noob question.
I'm checking out Laravel 4 but am totally new to the whole composer way of working.
I've set my composer.json as follows:
{
"require": {
"illuminate/foundation": "1.2.*",
"anahkiasen/former": "dev-composer"
},
"autoload": {
"classmap": [
"app/controllers",
"app/models",
"app/database/migrations",
"app/tests/TestCase.php"
]
},
"minimum-stability": "dev"
}
I've then run composer update
which all goes through OK.
Then I try to user Former in my app. I've tried Former::group('label.label')
in views, route closures and controllers . Each time I get a fatal error Class 'Former' not found
.
I guess I'm missing a step - do I need to use
a namespace in my controller to get access to Former?
I've attempted to debug the class loader. I've noticed that it's trying to load /vendor/anahkiasen/former/src//Former.php
instead of /vendor/anahkiasen/former/src//Former/Former.php
(the double slashes are present in everything the autloader is checking for).
If it helps, I notice two entries relating to Former in autoload_namespaces
'Laravel' => array($vendorDir . '/anahkiasen/underscore-php/src/', $vendorDir . '/anahkiasen/former/src/'),
'Former' => $vendorDir . '/anahkiasen/former/src/',
but nothing in autoload_classmap
I'm running this all under out-the-box PHP Version 5.4.6-1ubuntu1.1
Hi there, this is more a questions than an issue.
I'm trying to append form elements to my form dynamically through ajax, the idea is that the user can add many options of this field as he/she wants.
So I don't need to open another form tag for these elements because I'll append to inside an existing form. But the problem is when I create my form elements in another page, that I'll load through ajax, the form elements doesn't render properly if I don't user the Former::open() function.
There is/are any thing I can do to the form elements render properly without need to call the function Former::open();
Hope my question make sense, sorry for my english
Will this package be amended / forked to support Laravel 4?
Given the following blade template
{{ Former::horizontal_open('users/save')->withRules(array()) }}
{{ Former::xlarge_text('email', __("users.email_address")) }}
{{ Former::password('password', __("users.password")) }}
{{ Former::actions(Form::submit(__("users.save_button"), array('class'=>'btn btn-primary')) ) }}
{{ Former::close() }}
The Email field doesn't get rendered, but if I remove the withRules() call, it does. Any ideas what the problem might be?
The correct branch for L4 is agnostic, right?
In the documentation, the facade for L4 is described as:
'Former' => 'Former\Facades\Former',
Shouldn't this be
'Former' => 'Former\Facades\Illuminate',
When I populate a form from an Eloquent model then try to populate a field, I get the error :
"Cannot use object of type ObjectName as array".
I fixed it on my side by replacing the content of poulateField() by this :
if (is_object(static::$values)) {
static::$values->$key = $value;
}
else {
static::$values[$key] = $value;
}
I am surprised this issue wasn't already discussed ?
Hi,
Great work on this bundle. I wondered if you had considered supporting a different client side validation framework? For example, to support jQuery Validate (https://github.com/jzaefferer/jquery-validation) you would only need to make a minor change to the Filed::addRules() method
$this->attributes['data-validations'] = implode('|', array_keys($rules));
Putting this in would add the necessary 'data-validations' attribute to the element which should support most of the basic rules
Thanks
James
I'm surprised this doesn't work...
Hey, i use your excelent Bundle all over my application, but on my actually Application i have some Forms on a Modal.
The Modal is created by Twitter Bootstrap
I have this Modal Template:
{{Former::vertical_open()}}
{{Former::token()}}
<div class="modal-header system">
<h3>@yield('modal-title')</h3>
</div>
<div class="modal-body system">
@yield('modal-content')
</div>
<div class="modal-footer system">
@section('modal-footer')
<button class="btn" data-dismiss="modal" aria-hidden="true">Abbrechen</button>
<button class="btn btn-danger">Löschen</button>
@yield_section
</div>
{{Former::close()}}
and a file like this:
@layout('templates.modal')
@section('modal-title')
Form Element Textfeld hinzufügen
@endsection
@section('modal-content')
{{Former::text('name')->label('Nur ein Test')}}
@endsection
@section('modal-footer')
<button class="btn" data-dismiss="modal" aria-hidden="true">Abbrechen</button>
<button class="btn btn-success">Hinzufügen</button>
@endsection
but Former is not working correctly. Former is not using the label tag. When i write the line direct on the modal template file it works, but not with the dynamic view.
Have you an idea, how i can make it work?
Sorry for my English but iam German....
Kind Regards
Bug on line 197 : trying to check for the current Form's type when there is no actual instance of Form opened.
Hi,
Is is possible to render two controls (for example a textbox and a select) alongside one label? I've tried using prepend/append but that doesn't give me what I need.
I guess ideally I'd be able to open a control group (with a label), then add controls (which would not render their own control groups), and the close the group. Something like
{{ Former::control_group_open('label.label')}}
{{ Former::xlarge_text('value', false)}}
{{ Former::select('values', false, $value_list) }}
{{ Former::control_group_close() }}
Is this possible?
Thanks
I'm using placeholders for a few fields and would therefore like to disable the <label>
entirely, but can't.
I've tried this:
Former::xlarge_text('username')->placeholder('Username')->label(null)
and also tried passing false
, ''
, and 0
to the label() method ... all to no avail!
Any chance you could make it work so passing null
to the label() method disables outputting the label entirely? Alternatively, how about a no_label() method?
Thanks!
Need to check if when setting a custom id to a field, it remains linked to its datalist.
Hi,
Me again - apologies but I seem to have come across another error
I've now come across an error in Select.php on line 95
public function select($selected)
The error I get is
Redefining already defined constructor for class Former\Fields\Select
I'm calling it via
Former::select('foo')->fromQuery(Country::all(), 'name', 'id')
I'm going to see if I can upgrade my PHP version to 5.4 to see if it gets rid of it. I could just rename the function to something else, but I'd have to dig through and find all the references
In the readme for L4 you have the Fascades setting as 'Former' => 'Former\Facades\Former'.
Should it be 'Former' => 'Former\Facades\Agnostic' ?
Main objectives are :
When creating a radios() element each radio button in the array gets the same ID.
Also when creating checkbox elements there is no default ID and when you set ID, all the checkboxes get the same ID.
unless I'm missing something (I usually am :) ), should one be able to do the following for checkboxes and radios?
Former::radios('radio')
->radios(array(
array('label' => 'my text', 'id' => 'myID'),
array('label' => 'my text', 'id' => 'myNextID'),
))
See #12 for source syntax.
Hi,
I'm getting an error when trying to render the form with a text input as below
Class '\Former\Fields\Input' not found
bundles/former/libraries/former.php on line 101
No sure if this is a config thing on my server or something else?
When the label string is also the name of a language file, the following error kill the script :
ucfirst() expects parameter 1 to be string, array given
At : bundles\former\src\Former\Helpers.php on line 59
$page is a model with the following attributes:
Array
(
[id] => 2
[title] => Contact
[active] => 0
[created_at] => 2012-10-22 18:16:26
[updated_at] => 2012-10-22 19:02:44
)
My controller does this:
Former::populate( $page );
And my view:
{{ Former::checkbox('active') }}
The resulting output is:
<div class="controls">
<input type="hidden" name="active" value="" id="active">
<input checked="checked" id="active" type="checkbox" name="active" value="0">
</div>
So, it's checking the box even when the value is empty. I suspect that this is because I need to do this:
{{ Former::checkbox('active')->value(1) }}
... which indeed works, but doesn't seem entirely intuitive. Can we disable the insertion of those hidden fields (to pass values when the checkbox isn't checked)?
I have a User model with many-to-many relation to Roles. In my controller:
$user = User::with('roles')->find($id);
$roles = array();
foreach (Role::all() as $role) {
$roles[] = array(
'label' => $role->name,
'checked' => $user->has_role($role->name) // boolean if user has the role
);
}
Former::populate( $user );
Former::populateField( 'roles', $roles );
And in my view:
{{ Former::checkboxes('roles') }}
It obviously doesn't work, but what I'm hoping to get is a list of checkboxes, one for each of all the Roles (labelled with the $role->name
, valued with $role->id
) and those that exist for the current user are checked.
Is there an easy way to do this?
A feature request for the select field. Now only basic select and multiselect fields are supported, so I'd love to see support for optgroups in select fields.
When writing echo Former::radios('agreement')->radios('Non', 'Oui');
, Former uses the same ids and for
tabs for both elements, which breaks label clicking behavior:
Compare:
<div class="controls">
<label class="radio"><input checked="checked" id="agreement" type="radio" name="agreement" value="0">Non</label>
<label class="radio"><input id="agreement" type="radio" name="agreement" value="1">Oui</label>
</div>
to Bootstrap's examples:
http://twitter.github.com/bootstrap/base-css.html#forms
Cheers!
In L4 (agnostic branch), when I populate a form and add a checkbox like this:
Former::checkbox('admin')
Former::populate($user)
I get a checkbox like this for value=0
<input id="admin" checked="checked" type="checkbox" name="admin" value="0" />
And this for value=1:
<input id="admin" checked="checked" type="checkbox" name="admin" value="1" />
But this is incorrect. Checked should change depending on the original value, and the input value should always be 1. Otherwise you can't do something like:
$user->admin = \Input::get('admin') ? true : false
Because when checked, the value is still 0.
And with value=0, it shouldn't be checked..
legacy
, composer
and agnostic
branchesLike:
<?= Former::text('name')->groupClass('whatever') ?>
To create
<div class="control-group whatever>...</div>
Still have to investigate on that since I can't seem to reproduce it.
ErrorException: Runtime Notice: Non-static method Former\Former::framework() should not be called statically, assuming $this from incompatible context in /app/views/posts/edit.php line 3
I had Former::framework(null); just like in your example.
I have a problem with the select.
echo Former::select('price_list','Price')->options($price_list);
The problem is that this returns me an error saying that element 1 has to be a string...
But what I want is that to retrieve a table with id and price as columns and show the values in a selectbox....
Any ideas?
Thanks,
Ara
Hi Anahkiasen;
Will Former follow Bootstrapper V4, becasue there some class name changed in Bootstrapper V4, I suppose Former will got some impacts.
Regards, Mark
See this page for code reference – doesn't look that difficult to accomplish so far.
How can I get HTML like this with Former?
<label for='value_01'>
<input id="value_01" type="checkbox" name="values[]" value="value_01">Value 01
</label>
<label for='value_02'>
<input id="value_02" type="checkbox" name="values[]" value="value_02">Value 02
</label>
When using
{{ Former::actions( Former::submit('submit') , Former::reset('reset') ) }}
the output of the two buttons have the same value as below.
<div class="form-actions">
<input type="reset" value="Reset">
<input type="reset" value="Reset">
</div>
Unless I'm missing something, there isn't a Former::
method for buttons. So my templates look nice and lovely until I get to this:
{{ Former::actions(Form::submit('Save', array('class'=>'btn btn-primary')) ) }}
How about adding a Former::submit
and/or Former::button
?
When I do this:
Former::select('author')->fromQuery(User::all(), 'username', 'id');
Instead of outputting the expected, I get the output all weird with the JSON thrown in:
<select name="author" id="author">
<optgroup label="�*�items">
<option value="0">
{"id":"1","username":"admin","name":"Admin","created_at":"0000-00-00 00:00:00","updated_at":"0000-00-00 00:00:00"}
</option>
</optgroup>
<optgroup label="�*�dictionary">
</optgroup>
</select>
Any idea what's going on here?
Thanks
OK this is not exactly a bug in Former but rather in the Processing of a Form.
If a checkbox is not checked, the value does not get sent to the Server.
A possible solution is showed here: http://iamcam.wordpress.com/2008/01/15/unchecked-checkbox-values/
maybe you want to implement this.
Here's the scenario: I have a Project model with name, description, and a has_many relationship with Categories. Name and description are just text fields, and I want a text field with a comma-seperated list of the category names.
In my controller:
Former::populate( $project );
and my view:
{{ Former::xxlarge_text('name')->require() }}
{{ Former::xxlarge_textarea('description')->rows('5') }}
{{ Former::xxlarge_text('categories') }}
This works for the "name" and "description" fields, but will fail for the category list.
So I try overriding the value for that one field:
Former::populate( array('categories' => $project->relation_list( 'categories' ) ) );
Well, that's now overwritten all the other fields, and there is no Former::set_value()
to handle this.
The only solution (I think) is to rename my form field to "categorylist" instead of "categories" and a custom getter to my Project model:
public function get_categorylist()
{
return $this->relation_list( 'categories' );
}
Hi,
Is it possible to submit the form when a value is selected in a drop down menu?
I am trying to do a table with results and I need a select box for filtering/sorting...
Thanks,
Ara
In Laravel 3, when you are defining a field and you use the "class" function, the field comes just with the new classes instead of come also with the size classes.
For example, if you have the following code:
{{Former::mini_text('currency')->prepend('$')->required()->class('currency')}}
Instead of render the code:
<div class="control-group required">
<label for="currency" class="control-label">Currency<sup>*</sup></label>
<div class="controls">
<div class="input-prepend">
<span class="add-on">$</span>
<input class="input-mini currency" required="true" type="text" name="currency" id="currency">
</div>
</div>
</div>
It renders the code:
<div class="control-group required">
<label for="currency" class="control-label">Currency<sup>*</sup></label>
<div class="controls">
<div class="input-prepend">
<span class="add-on">$</span>
<input class="currency" required="true" type="text" name="currency" id="currency">
</div>
</div>
</div>
This was you keep the consistence of the code, declaring all the sizes with the field declaration instead of put the size as a class for the fields that you want to have an extra class
It would be nice to be able to output a block of text/HTML within a form, but that didn't include form-fields, but lined up nicely with everything else. Something like this:
<div class="control-group">
<div class="controls">
Forgot your password? <a href="###">Click here.</a>
</div>
</div>
Right now, I've got a bunch of Former::
methods in my template, and then I have to break back to HTML to output the above. Being able to do it "natively" would be nice, maybe something like:
{{ Former::textblock('Forgot your password? <a href="###">Click here.</a>'); }}
Just a suggestion!
Hi,
I am having a tough time with the checkboxes.
I want to have a table with checkboxes in a row of a table. The table is populated with users. I need to be able to retrieve the users id of the rows that has been checked....
Is there a way?
Thanks,
Ara
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.