Push button enabled with editable text box
4 views (last 30 days)
Show older comments
Hello,
Hopefully my question is rather straightforward and easy to answer. Basically what I want to do is make it to where my push button is disabled until text is being entered into an editable text box. This will prevent the user from progressing to the next screen in the GUI without entering in data. I have it "functioning" now, but not quite like I would want.
Right now I have it to where the person can put a string or number in the text box and then when they click outside the box anywhere (to allow the system to know they are done editing, similar to exiting the field in normal applications). This is not user friendly though and can definitely be improved in someway. I just want it to be where as they are typing the button is enabled.
The code I am using currently is this:
function TypePartNo_Callback(hObject, eventdata, handles)
fileName = get(hObject, 'string');
if isempty(fileName)
set(handles.Enter, 'enable', 'off');
else
set(handles.Enter, 'enable', 'on');
end
Where "TypePartNo" is the editable text box and the function is the callback of the text box. "fileName" is used to retrieve the string typed in. "handles.Enter" is the handle for the enter push button that I want enabled and disabled.
Hopefully there is a simple way to fix this because as of now it does not appear as if "fileName" is able to pick up on any change until the cursor is not in the text box.
Thank You in advance for your help.
0 Comments
Accepted Answer
Jan
on 25 Jun 2014
You could catch the event of adding characters in the edit field in the Java level. See http://undocumentedmatlab.com/blog/category/ui-controls.
Another easy method yould be to enable the button and peform a check, when it is pressed. Then the missing fields are highlighted or a message box appears to explain the problem. This is a usual methods e.g. in many web interfaces.
2 Comments
More Answers (0)
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!