This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hello, would it be possible, based on the tuto of Ivan Doric (https://watch-learn.com/video-tutorials/making-websites-with-october-cms-part-10-relations) to show/hide the 'Genre' relation widget, depending on another boolean field ?
I made this working with a standard field with a YAML dependsOn and a hidden value set in filterFields().
With : $fields->types->hidden = true; I receive : Model 'XXX\Models\Event' does not contain a definition for 'types'.
Do you have any ideas for doing this with the widget ? Thanks
Last updated
Here is my code. It works if I put hidden:0 or 1 in the YAML, but not with code.
YAML :
tabs:
fields:
categ:
label: 'Catégorie d''événement'
type: radio
tab: Catégorisation
types:
label: 'Types d''événement'
nameFrom: type_nom
descriptionFrom: description
type: relation
tab: Catégorisation
Model :
public function filterFields($fields, $context = null) {
$bExclus = \DB::table('lb_events_categs')->where('id', $this->categ)->value('categ_exclusive');
// If exclusive category then hide types
if ( $bExclus == 1 ) {
$fields->types->value = 0;
$fields->types->hidden = true;
$fields->event_ontv->value = 0;
}
}
Last updated
the filterFields method will get called when the Form get rendered initially, then when the onRefresh ajax handler gets called (mainly from dependent fields being updated)
filterFields() is correctly called when I make changes, but $fields->types->hidden = true; has no effect, the field "types" is not hide.
You're right ! "dependsOn: categ" is needed in YAML.
I thought the dependsOn was not needed as the code could do it programmatically.
Thanks a lot !
In complement, how could I change the switch value with dependOn, based on my query (3rd post) ?
Do I have to understand that I could do it in a query in the YAML ?
https://octobercms.com/docs/backend/forms#field-switch
Yaml :
event_ontv:
label: 'Diffusion TV'
type: switch
dependsOn: categ
tab: Catégorisation
Last updated
Well I just realized that with the following code, the line $fields->event_ontv->hidden = true; is disturbing the dependOn and causing the problem.
If I comment it out, it's working !
if ( $bExclus == 1 ) {
$fields->types->value = 0;
$fields->types->hidden = true;
$fields->event_ontv->value = 0;
$fields->event_ontv->hidden = true;
}
Could this be a problem of October ???
Last updated
1-10 of 10