Skip to content

readOnly attribute not working on Autocomplete field #177

Open

Description

@dtannen
        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.

Activity

  1. beliolfa commented on Jul 27, 2020

    @beliolfa
    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!

  2. NeroAzure commented on Feb 1, 2021

    @NeroAzure

    @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)).

  3. beliolfa commented on Feb 15, 2021

    @beliolfa
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions