Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readOnly attribute not working on Autocomplete field #177

Open
dtannen opened this issue Jun 29, 2020 · 3 comments
Open

readOnly attribute not working on Autocomplete field #177

dtannen opened this issue Jun 29, 2020 · 3 comments

Comments

@dtannen
Copy link

dtannen commented Jun 29, 2020

        Autocomplete::make('Field', 'field')
                ->options($this->getFieldOptions())
                ->placeholder('Choose a field')
                ->displayUsingLabels()
                ->rules('max:255', 'nullable')
                ->hideFromIndex()
                ->readOnly(function () use ($request) {
                    return true;
                }),

This field is no longer readOnly on 0.17.0 and Laravel 7 / Nova 3.

@beliolfa
Copy link
Contributor

Hey @dtannen sorry for the delay I took a little vacation.
Since this PR https://github.com/64robots/nova-fields/pull/167/files we are not redeclaring readOnly anymore so if you use the modifier as described in Nova Docs should work. Can you try and let me know if it works? If not, please, provide reproduction steps and I will try to fix it.
Thanks!

@NeroAzure
Copy link

NeroAzure commented Feb 1, 2021

@beliolfa It seems like you are still referencing your readOnly attribute inside your vue components, which itself is looking at this.field.readOnly. Meanwhile Nova has its on computed property for that called isReadonly, in which readonly (see the lowercase o) but also this.field.extraAttributes.readonly are looked at, the latter is the property which is set by Nova-fields.

This results in the behaviour that your fields are not displaying as readonly, but behave that way (value does not get saved).

Additionally, the JSON field will save values even when a field inside it has been marked as readonly, as a workaround for our project I extended your JSON-class and changed fillAttributeFromRequest, so that the fields that are readonly get rejected before filling (via ->reject->isReadOnly($request)).

@beliolfa
Copy link
Contributor

Hey @NeroAzure thank you for your detailed solution. It looks like you fixed the issue in your projects. Do you mind opening a PR so I can take a look? If you are busy I will fix it as soon as I can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants