This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I'm trying to get a relation field to always be 'empty' by default, as of now, I setup a 'belongsTo' relationship, but everytime I create a new record in the database, it displays the first item in the list, although not selecting the actual id for the relation.
I tried setting the 'emptyMessage' option to the field, but I still get the text displayed.
I want this field to be optional (can be empty) so I set it as nullable in the database, and not required.
I'm trying to set an 'optional parent field', so the relation is to the same model:
public $belongsTo = [
'optionalselect' => ['Victor\Test\Models\OptionalSelect'],
];
in fields.yaml the related information is:
fields:
optionalselect:
label: 'optional select'
span: full
type: relation
emptyMessage: 'empty'
Is there an implemented way to do this? Am I doing something wrong?
Last updated
Self-answering myself, what I was looking for was the 'placeholder' or 'emptyOption' option, as described in the documentation in the Backends->Forms->DropDown section ( http://octobercms.com/docs/backend/forms#field-dropdown) .
placeholder: 'Select parent'
or
emptyOnly: 'Select parent'
Last updated
1-2 of 2