Switch between view and edit mode in a modal window

I am using the framework you have shown in How To Create A Modal In UI Builder | Backendless and I want to enhance it a little bit. I want to use it as a form for showing content and changing content. Therefore I provide a Pencil Icon :pencil2: with an on-click event logic. On clicking the pencil all input fields should be enabled for editing. It sounds simple - loop through all fields in the DOM and enable editing (set Disabled to False).

But, somehow I cannot manage it to find the fields in a generic way during runtime. I have to list all fields by name during design time and enable them. But, I want to do it during runtime, even after adding a new field during design.

Any idea how to accomplish this task with Codeless and the UI Builder?

Hello @Jorg_Beyer!

I would recommend you to use one variable, readOnly for example.

The value of which will change when you change the mode.

And use this variable to enable/disable editing in all fields.

Regards,
Alexander

:clap: A beautiful and simple solution by @Alexander_Pavelko. Many thanks for this - I was thinking much too complicated and forgot about data binding.

With regards to the modal window: I initialize the variable everytime when I click to open the modal and back when I close the modal. And, I change the mode in the “Disabled State Logic” handler, because my Select Field has no “Read-Only State Logic” Handler.

1 Like

Hello @Alexander_Pavelko, I have tried the solution and it worked. But I have now switched the element to a reusable component using the reusable component data model. Here I experiencing the problem, that the events are not executed the same way like before. That means, when I change the read-only state to true, the elements do not change their state to editable. And, even the save and cancel button will remain visible. Any idea why this could happen?

Hello @Jorg_Beyer!

I will try to reproduce this issue, but in my case the reusable component works correctly.
Could you please give me more information about the changes what you made?

Regards,
Alexander

I set the readOnly flag in the Reusable Component Data Model and not at Page Data Level. This is more or less the only change.

Could you check if readOnly changes when you try to change the state (you can use print for example)?
And please add screenshots of the changes you made.

Regards,
Alexander

Here are the changes.
This is the click event for the readonly state.


The Cancel Button is resetting the state

The readonly state of the itemName field is depending on the readonly state

After open the modal frame and clicking the edit Button this is the console output. ITEMNAME is the text field which I want to edit. It is set to false but I cannot edit it.
image

1 Like

Could you please tell me on which page of your app is this logic located?
And how do I reproduce the issue?

Regards,
Alexander

the Page Name is expenses but the logic is in the Component expense_modal. The modal will be opened by clicking on the itemName Text Field in the Repeater Container. In the expense_modal Component the important logic for the readonly state is located in the three Icons on the right hand side.

Thank you. Is this page in this app A2090C1B-936C-A876-FF32-277A55A60700?

Regards,
Alexander

Nope, D550D917-6D17-7B42-FF4A-3A24CD89B300

There is the reason

Class List is triggered after every change in data model, so it’s set readOly = true after click on edit button.

Regards, Dima.

Thank you @Dima. I see that this solves a problem. But, when I am binding the editable fields to the readonly state then the fields do not change their behaviour. Only if I am binding the state to the Disabled State Logic the behaviour is as expected. Any idea why this is the case?

And, where should I initially set the readonly state to true if not in Class List Logic?

And, where should I initially set the readonly state to true if not in Class List Logic?

When open the modal, or at mount events.

But, when I am binding the editable fields to the readonly state then the fields do not change their behaviour. Only if I am binding the state to the Disabled State Logic the behaviour is as expected. Any idea why this is the case?

Could you create a minimal reproducible example of this issue? That will makes investigation a lot easier.

done, it works.

done. Investigationg on my own. It seems to work, but the text field does not show a different text format for read-only and editable. I will look for the CSS formatting.

Thanks so far for your support.