I'm working on a small component and depending on $someoption
I need to remove a certain option from the JForm
. So for example if $someoption == 1
then I need to remove this option <option value="1">COM_MY_FIELD2</option>
.
I only know how to set the whole field to hidden
via setFieldAttribute
, but how to remove only one option?
Here is the XML Form part:
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset>
<field name="field1" type="radio" default="0" label="COM_MY_LABEL1" class="btn-group btn-group-yesno">
<option value="0">COM_MY_FIELD1</option>
<option value="1">COM_MY_FIELD2</option>
<option value="2">COM_MY_FIELD3</option>
</field>
...
Here comes the preprocessForm Function from the model:
protected function preprocessForm(JForm $form, $data, $group = '')
{
$app = JFactory::getApplication();
...
if ($app->isClient('site')) {
if ($someoption == 1) {
// this sets the whole field to hidden
$form->setFieldAttribute('field1', 'type', 'hidden');
}
}
parent::preprocessForm($form, $data, $group);
}
...
$someoption
come from? Will showon not work for your project? May we learn more about the context of your question?