Field in smart action looses its readOnly property after a hook executes

Expected behavior

In the Smart action there’s a field that is configured to be read only. When a hook is executed on that smart action, that field should remain as read only.

Actual behavior

When a hook (in my specific case, a load hook) is executed on the smart action, the field that was read only looses its read only property and can now be edited.

Context

Please provide any relevant information about your setup.

  • Package Version: 7.0.1
  • Rails Version: 6.1.4
  • Database Dialect: Postgresql
  • Database Version: 13.2
  • Project Name: Back Office

Hey @sergior,

Could you share the definition of your smart action?
I just did a quick test on my end and I’m currently not able to reproduce with this setup

  action 'Debug readonly',
    type: 'single',
    fields: [
          {
            field: 'Boolean with a onChange',
            hook: 'onBooleanChange',
            type: 'Boolean',
          }, { 
            field: 'ReadOnly that should remain readonly',
            type: 'String',
            isReadOnly: true,
          } 
        ],
    hooks: {
        :load => -> (context){
          context[:fields].push({
            :field => '(Added on load)',
            :type =>  'String',
          })
          return context[:fields]
        },
        :change => {
          'onBooleanChange'=> -> (context){
            context[:fields].push({
              :field => '(Added on change) Send to',
              :type =>  'String',
            })
            context[:fields]
          },
        },
    }

Hi @jeffladiray ,

After a little bit more debugging and also trying to use your example, I’ve managed to figure out the culprit.

In my definition, I’m setting the field properties using the ruby convention snake_case, e.g. is_read_only instead of the camelCase version isReadOnly. The camelCase version seems to have been deprecated by you anyway

So I avoided to use those anyway.

The Javascript in ForestAdmin UI uses the response of the hook to re-render the smart action screen but what’s being returned when using the snake_case definitions is not compatible and therefore ignores the read only definitions.
Also (something I’ve noticed during my debugging), the is_required definition suffers from the same issues: the *s disappear and the fields that are expected to be required become optional and I can submit the form without a presence validation error on those being shown as expected).

Hey @sergior,

My bad on this one, I’m totally able to reproduce this issue… I didn’t notice the DEPRECATION WARNING while doing my tests (Since it was working because of the code you mentioned).

I’m opening a ticket on our end with your analysis since it is a 100% right.
While we’re working on it, the “best” workaround I can propose is to re-set in theses values in the load hook.

Sorry for the inconvenience, and be sure you’ll be ping once fixed.

1 Like

Hey @sergior,

We’ve just released a new version of forest_liana@7.0.2 that should hopefully fix this issue.
You should be able to use the is_read_only ruby notation.

Let me know if that’s the case or if you still encounter any issue :pray:

1 Like

Thank you for addressing the issue so promptly.