How do I add .editable behavior to .mlapp components?

Some mlapp components have a .editable property that allows or disallows editing of the value. An example is the numeric edit field, where you can allow or disallow editing the value displayed by setting the .editable property for the component. However, not all components that hold a value have a .editable property. An example of this is the check box. The check box has a value (app.checkbox.Value) that can be changed by clicking the check box, but there is no .editable property that I can set to allow or disallow this editing.
Is there a way to add this .editable property and behavior to mlapp components that lack it? examples of components that lack the behavior include the check box, switch, dropdown menu.
For context: I'm building a gui in the matlab app designer that will control an expensive piece of equipment. The equipment has many settings that the user may adjust via the gui. I have a switch on the gui called "enable editing" that sets the .editable status of all edit fields to off unless the switch is flipped to the on state. This acts as a safety to prevent unintended and potentially damaging changes to the configuraion. This setup works perfectly for all of the numeric edit fields but I can't figure out how to add this safety feature to check boxes, switches, and dropdowns.
It is possible to set the .enable property on these components to off, but that has unintended consequences from a user interface perspective. Components are greyed out and very hard to see while disabled, which communicates to the user that the setting is not relevant, isn't used, or something along those lines. That's not at all what I want. The current state of the check box is extremely important and should remain perfectly visible - I just don't want a misclick to change its status. I've made a quick dummy app showing the difference using a check box. A screenshot is shown below.

 Accepted Answer

There is not an 'Editable' property for checkboxes. Since it appears you want the checkbox to be view only, which means its value is getting set programmatically elsewhere in your app, you could make the checkbox callback just be a function that returns the checkbox back to whatever value it had before.
% Value changed function: CheckBox
function CheckBoxValueChanged(app, event)
value = app.CheckBox.Value;
if value==1
app.CheckBox.Value = 0;
else
app.CheckBox.Value = 1;
end
end

4 Comments

Jeff
Jeff on 30 Mar 2023
Edited: Jeff on 30 Mar 2023
The value is being set manually by the user clicking the box. The .editable property is what I'm changing (or rather want to change) programmatically. I just want the ability to control when the check box accepts new manual user inputs so that I can allow the user to look at the setting without the potential for a misclick changing the setting.
Essentially, I want the ability to programmatically flip back and forth between view only and editable state. I'll have a callback controlled by another component that determines the view only vs. editable state but then the user needs to click the checkbox to change its value.
Got it.
There is no editable property to set, so any solution will require programming a custom solution. An idea that comes to mind is creating your own app property that is a flag for when the check box is editable, and incorporating that flag into a logic statement that determines when to allow changes to the checkbox.
% Value changed function: CheckBox
function CheckBoxValueChanged(app, event)
value = app.CheckBox.Value;
if app.editFlag == false & event.Source.Text == "Check Box"
if value==1
app.CheckBox.Value = 0;
else
app.CheckBox.Value = 1;
end
end
end
Jeff
Jeff on 30 Mar 2023
Edited: Jeff on 30 Mar 2023
I just tried this and it works. It's a little hacky but it gets the job done for now. The downside is the value still does change for a moment - the checkbox flickers when I click it while editFlag is false but it does quickly resume its prior state. This could be an issue for other applications where a momentary change in the state is a problem but it's not a concern for my application.
I think this is something that should be looked at for a future release though. It seems to me that a Value property should always go hand-in-hand with an Editable property. There's no fundamental difference between a numeric edit field and a check box - they're both ui components that store a value and may be changed by the user. The only difference is the domain of valid Values and how it appears on the interface. If one has an Editable property, all others should as well.
Agreed. Consider submitting a suggestion saying as much here:
(Create Service Reqeust > Technical Support > Product help, bugs, suggestions or documentation errors)

Sign in to comment.

More Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Asked:

on 29 Mar 2023

Commented:

on 30 Mar 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!