Code Monkey home page Code Monkey logo

former's People

Contributors

adamfeuer avatar anahkiasen avatar andrewryno avatar barryvdh avatar cednet avatar claar avatar dariusj18 avatar dowilcox avatar dwightwatson avatar fonograph avatar gazard7 avatar ignaciovazquez avatar jridgewell avatar luukholleman avatar maqnouch avatar menthol avatar michelbrito avatar msurguy avatar nelind avatar patrickcarlohickman avatar petercoles avatar rmasters avatar rmobis avatar sawyerhopkins avatar stayallive avatar syphernl avatar tortuetorche avatar vlakoff avatar weotch avatar wisepotato avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

former's Issues

Same ID on radios element

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'), 
    ))

Any way to disable a label for a field?

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!

Better submit buttons?

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 ?

Ability to create label-less text blocks.

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!

Add form elements dynamically with ajax

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

Grouping controls

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>

Possible bug in Former::action

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>

How to use in Laravel 4?

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

Strange Validation problem

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?

Problem with select

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

Wrong checkbox value

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..

Class load error

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?

Error

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.

Facade for L4

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',

L4 - Agnostic Fascades setting

In the readme for L4 you have the Fascades setting as 'Former' => 'Former\Facades\Former'.
Should it be 'Former' => 'Former\Facades\Agnostic' ?

"class" function override default class

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

Redefining constructor error

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

Will former follow bootstrapper V4

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

Checkboxes

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

"Try" to make Former framework-agnostic

Not actually up to date, things work actually better than this

  • Abstract Former's app dependency
  • Merge the legacy, composer and agnostic branches

Laravel 3

  • Static facade
  • Markup
  • Populating
  • Repopulating
  • Custom configuration file
  • Localization
  • Errors handling
  • Live validation

Laravel 4

  • Static facade
  • Markup
  • Populating
  • Repopulating
  • Custom configuration file
  • Localization
  • Errors handling
  • Live validation

Stand-alone

  • Static facade
  • Markup
  • Populating
  • Repopulating
  • Custom configuration file
  • Localization
  • Errors handling
  • Live validation

Bug with Form instances

Bug on line 197 : trying to check for the current Form's type when there is no actual instance of Form opened.

Submit on dropdown menu selection

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

Error when populating field after populating the form with object

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 ?

Allow optgroup in select

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.

Checkboxes not working?

$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)?

Support jQuery Validator?

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

Can't overload populate() for one field

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' );
}

Check box check function weird functionality

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;
    }

Error with Bootstrapper Modal

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

Populate checkboxes from Eloquent relation

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?

Is it possible to render two controls alongside one label?

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

Select -> fromQuery wrong output

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

Specifying the same `for` and `id` breaks clicking behavior for checkboxes and radios

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.