auraphp / Aura.Input

Tools to describe HTML form fields and values.
MIT License
65 stars 11 forks source link

What about automatic id #17

Closed harikt closed 11 years ago

harikt commented 11 years ago

I noticed currently when the id is not specified the id field is null, what about assigning the same name for the id, if it is not specified..

I feel this is good option else we may want to specify at many times,

pmjones commented 11 years ago

Not sure what you mean here.

harikt commented 11 years ago

so normally when you assign a field, you need to specifically set the attribs id , as in view it will come like <input type="text" name="somename" id="somename" /> . What I mean is even if you don't provide an id field, just name the id same as name.

pmjones commented 11 years ago

It would have to be based on the full name, not just the name. E.g. if you have a form with a "foo" fieldset and a "bar" fieldset, and the both have an "id" field, the ID names would clash. You would need to convert the full name, e.g. "foo[id]" and "bar[id]" to unique ID names. If you want to provide a patch for that, I'd be happy to review it.

harikt commented 11 years ago

I didn't mean the id as same. I was thinking giving same name as the id . So in your example,

if (empty($field['foo']['id'])) {
    $field['foo']['id'] = $field['foo']['name'];
}

I will look how I can come up.

pmjones commented 11 years ago

Still not quite good enough. IDs need to be unique. If you have two fields in two different fieldsets with the same name, the IDs will be invalid. You need to take into account the full name not just the name.