Conditional display - toggling readonly state of form input field, or just show/hide input field

Hi,
Having problem trying to get this working. Not sure where I am going wrong.

I am trying to make a form input text field ‘readonly’ when it contains data from session storage value (which was passed from a previous form). If it dose NOT contain any data (i.e. is blank), then the text field should be editable and the readonly should be removed

This is my form input text field.
<input type="text" class="form-control" id="inp_usr_username1" name="usr_username" aria-describedby="inp_usr_username_help" placeholder="Email" dmx-show="session1.data.usr_username.contains('')">

I have tried using ‘Dynamic Attributes’ for the input text field and apply a ‘Show’ or Hide’ and then select Conditional >> If contains. But I am struggling with the logic. I feel that I need a condition “If does NOT contain”, but the option isn’t there.

I am trying to make the input text field editable if the session variable is empty and not editable (ie. readonly) if the session variable contains data.

The other alternative that I have tried is to have two seperate input text fields and display only one of them if the condition is met.

My logic is:
Display input text field 1 (which is readonly) if session var is NOT empty
Display input text field 2 (which is editable) if session var IS empty

Just can’t get it to work!

I’ve worked out part of the issue, I can show/hide using operations (I didn’t see it before), so show !== and so one.

However, the code is still display when you view source page, but it just hidden from the users screen, so the form input text field is still being used even though its hidden from the user.

Is there a way to use conditions to completely hide the field and not appear in the code when rendered by the browser?

Try just using:
session1.data.usr_username
!session1.data.usr_username
.. for the conditions.

1 Like