Push button enabled with editable text box

5 views (last 30 days)
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.

Accepted Answer

Jan
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
Bryce
Bryce on 25 Jun 2014
Thank you for the quick response.
I will have to look into your first suggestion tomorrow when I have some more time to do some research.
On your second method, I have already done that and it worked the first time. I set the "fileName" with the setappdata function to open an image. I set it with a "0" to make it a root to where I can access it on the next GUI screen where the image is displayed. So when I run it a second time and the user does not type anything in, the image that was previously accessed pops up. I have tried to clear it using a simple "clear fileName" but this way does not work unfortunately. If the user types anything in, even if it is wrong, it functions as I have an error message come up. If there is nothing, MATLAB assumes it is the old image(and by MATLAB I mean i make it think that due to improper coding). The code I use to save and access the data is below:
setappdata(0, 'name', fileName);
PartNo = getappdata(0, 'name');
Bryce
Bryce on 26 Jun 2014
Hello all,
I have figured out how to fix my problem. As described in my previous comment, I am using the root function of setappdata so I needed to reset it upon the opening of that particular GUI page. I did this with this simple line of code:
rmappdata(0, 'name');
Hope this may help someone in the future.

Sign in to comment.

More Answers (0)

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!