Add "preset" attribute to form fields and adapt list/checkboxes multiple default/preset values #1257
Conversation
$html[] = JHtml::_('select.genericlist', $options, '', trim($attr), 'value', 'text', $values, $this->id); | ||
foreach ($values as $value) | ||
{ | ||
$html[] = '<input type="hidden" name="' . $this->name . '" value="' . $value . '"/>'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work? If they all have the same name I'd think only one would get send to the server.
We've had quite a big discussion on the platform list about how to store multiselect values, does this mean that the maintainers have reached consensus on this being the right approach? @Roveun I would think you need a test with this. |
@realityking , for multiple field the name is 'myname[]' (note the []) this is why you can store multiple value @elinw I don't see these posts. Can you post the urls here? |
…ple default/preset values
As far as I understand what Sam said, the platform wants to stay neutral in deciding whether multiple values are stored as normal strings, json strings or something else and basically it's up to developers to implement. So I'm not against making it possible to do this, I just want to be clear on what is being done here. This is just about the rendered form, not about what is saved. |
No problem to change preset="value|true" to selected="value|true" but for text fields selected="something" is not accurate |
Check boxes and lists are extremely different In text/textarea the idea of selected doesn't make sense since there is no select. So the proper rendered html is:
Checkboxes shoudl render http://www.w3.org/TR/html401/interact/forms.html For check boxes we already have the checked element . So to me the only real issue is in lists. |
In text/textarea, the idea of preset="Enter your text here..." can be used the preset attribute is only for fields edited the first time (text/list/checkboxes...) For examples, look at the test code If values are not present in the list, they will be ignored |
Closing this one (need to play with it) |
See #1280 |
It's a solution for Joomla CMS [#28402] JFormFieldList (and derivatives) do not utilize multiple default values when multiple=true (http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=28402)
It has been extended for supporting preset values in form fields
in an single valued field, you can now use
This will fill the field the first time the form is edited
in a list/checkboxes
This will fill the field the with 1 if the current value is empty
This will fill the field the with 1 the first time the form is edited
This will fill the field the with 1,3 if the current value is empty
This will fill the field the with 1,3 the first time the form is edited