How to check input right in template

46 Views Asked by At

Can I access the input value and check his value? I want to disable the ability to change the key if it's equal to 'foo'.

.email-template-param-nested-fields
  - if :key == 'foo'
    = f.input :key, placeholder: 'foo', readonly: true
  - else
    = f.input :key, placeholder: 'key'
  = f.input :value, placeholder: 'example'
2

There are 2 best solutions below

0
mechnicov On

You can assign variable as

- args = f.object.key == 'foo' ? { placeholder: 'foo', readonly: true } : { placeholder: 'key' }

And then

= f.input :key, **args
0
jeffdill2 On

You can do your conditional inline:

.email-template-param-nested-fields
  = f.input :key, placeholder: 'foo', readonly: (f.object.key == 'foo')
  = f.input :value, placeholder: 'example'