User tests: Successful: Unsuccessful:
Currently we are already able to add remove form fields from JForm, update field attributes in the preprocessForm triggers. One thing that has always bothered me is the inability to add new options the the list type form fields.
What I propose here might not be the best solution, however this can be a good point to start with.
Allow adding a new list option to JForm
fields.
Allow additional attributes to the option element created.
Allow adding <optgroup>
groups in the list options. (will be used only if form field class cares for)
JForm
instance with a list type form field.$form->addFieldOption('fieldname', 'value', 'Option Text');
on the JForm
instance.The new option should be visible in the list dropdown.
Update JForm documentation.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries Unit Tests |
Since 3.7. Great. I didn't notice it.
Now I see that the syntax by this PR is more straight and consistent with the $form->setFieldAttribute()
etc. and also offers more features.
This one may still be considered IMO.
I would then probably make the existing function as feature reich as your one. IMO we should not have duplicate ways of adding options.
About the duplicate, I completely agree.
Though adding option should not be limited to JFormFieldList
. See \JFormFieldText::getOptions()
I'd rather suggest modifying existing method to call this one in turn so as to not B/C failure, and also avoid code duplication.
Guess it is worth a try.
FormFieldText::getOptions()
That one is a different usecase than the one in JFormFieldList. The "options" in the text formfield are used for the datalist/suggestions. I wouldn't try to mix them as they support different attributes.
Adding an addFieldOption to the JForm class isn't wise as it would be useless for most formfields (only list types (checkboxes, radios, ... all extend that type) support oprions). I'd rather extend the existing JFormFieldList::addoption() with your proposed functionality. And if you really want you can add a similar method to JFormFieldText.
JFormFieldText method getSuggestions() was deprecated to make things
consistent. If these two are so much different in nature why did we do that?
JFormFieldText method getSuggestions() was deprecated to make things
consistent.
The initial reason for #3588 was a codestyle issue which couldn't be solved otherwise. When choosing a new method name I just took the one we use in other places. The method names are now consistent (which imho makes sense) but what it actually does will differ as datalist options and select (or radio and checkbox) options don't support the same attributes.
Labels |
Added:
?
?
|
I've made the changes. Please review.
I think the JFormFieldList method looks fine.
I don't like much the method in JForm. Why do you want that? One could as well just fetch the field and add it from there. The form method doesn't do anything else than some checks around
$this->getField($name, $group)->addOption($text, $value, $attributes, $optGroup);
Ok. Just one problem how do we know whether the $field->addOption is
callable. How do we avoid the overhead of checking it all the time in the
calling code.
Ok. Just one problem how do we know whether the $field->addOption is
callable. How do we avoid the overhead of checking it all the time in the
calling code.
I suppose in your extension code, you know which field you want to add some dynamic options. You will only call it for fields that allow them.
Of course if you're talking about a CCK then you don't know that, but then I would expect you to do those checks in your extension.
I have tested this item
Labels |
Added:
?
?
Removed: ? ? |
Sorry that it has taken so long to respond to this pull request. It is a nice addition and we would like to reconsider it for Joomla 4.2. Since this change will throw a warning in PHP 8 for subclasses overriding this function, it can't be accepted in the current stage. One solution would be to make a new function and deprecate the old one. We are closing it in the meantime. When ready please reopen again.
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-03-18 07:53:59 |
Closed_By | ⇒ | laoneo | |
Labels |
Added:
?
Removed: ? |
Just wondering, JFormFieldList has an addOption function, would that not work?