This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
In my editing form there are specific cases where some fields should be hidden.
public function filterFields($fields, $context = null)
{
if (condition) {
$fields->my_field->hidden = true;
}
}
The field disappears from the form as expected but the field is also removed from the source code.
As a result, when the form is saved, the field value is lost and a null value is applied instead.
How can I hide my fields without being removed from the source code ?
Last updated
Here it is:
public function filterFields($fields, $context = null)
{
if ($this->parent && $this->parent->attributes['status'] == 'unpublished') {
$fields->status->hidden = true;
$fields->parent->hidden = true;
}
elseif ($this->parent && $this->parent->attributes['status'] == 'published' && $this->status == 'unpublished') {
$fields->parent->hidden = true;
}
}
Maybe use the cssClass field option to hide it?
https://octobercms.com/docs/backend/forms#form-field-options
Did you also check trigger events?
https://octobercms.com/docs/backend/forms#field-trigger-events
Already did. Same result...
Could you try it in one of your plugins, just to make sure ?
Last updated
Sorry I skipped your post.
Yes it works. Actually in my case:
$fields->status->cssClass = 'hidden';
But I find the "hidden" attribute misleading. I was expecting it to modify the type of the field
<input type="hidden" name="Post[my_field]" value="hello" />
1-11 of 11