Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
hi, how can i use the command "ask" without the option "Cancel" because by default the system gives 2 options 1) "Ok" 2) "cancel"
but in my case i want to force the user to write something and if he clicks on "cancel" it will give an error any ideas? this is the code
on AskName
if field "UserName" is empty
then
ask "Enter username:"
put it into _guserName
put _guserName into field "UserName"
else
break
end if
end AskName
on AskName
if field "UserName" is empty then
## Hide that CANCEL button
hide btn "cancel" of cd 1 of stack "Ask Dialog"
ask "Enter username:"
put it into _guserName
put _guserName into field "UserName"
## Always good style to reset everything to avoid suprises. :-D
show btn "cancel" of cd 1 of stack "Ask Dialog"
end if
end AskName
Tested and works, however you still need to check if IT/_guserName = EMPTY!
Means the user did not enter any text, which may spoil this approach anyway....
on AskName
if field "UserName" is empty then
## Hide that CANCEL button
hide btn "cancel" of cd 1 of stack "Ask Dialog"
ask "Enter username:"
if it is empty then
answer"you haven't typed."
AskName
else
put it into _guserName
put _guserName into field "UserName"
## Always good style to reset everything to avoid suprises. :-D
show btn "cancel" of cd 1 of stack "Ask Dialog"
end if
end if
end AskName
That said, there is nothing wrong with hacking LiveCode, which is what he suggested. Everything in LC is a stack, including the "ask" dialog. Therefore, we have complete control over the very program we are using to do stuff.
I just would not have considered that. Not sure why, really, I would have made a modal stack that looks like a cancel-less ask gadget. Just a matter of style.
i didn't know that, do you have any idea how to force the user to type a username?
(because i thought abut a text field but then he could just miss it or don't type...)
thanks.
Samuele wrote: Mon Nov 15, 2021 5:12 pmi didn't know that, do you have any idea how to force the user to type a username?
no, sorry.
But why not just leave the CANCEL button in place and if the user does not enter anything,
well, he/she might just not want to use your app. At least I would do it this way.
I'm with Richard, I wouldn't use an ask dialog. It's discouraged now because it's intrusive and dated. You won't see them anymore in modern apps.
Instead, just use a field. You can check if the field has content when the user tries to proceed. If you have a Submit button or a Next button, check there. Or check on closecard and if the field is empty then do not go to the next card.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
Or, again, if you want such a gadget as a UI thing, then make a subStack that looks just the way you want it. It may seem overkill to make a whole new stack just to act as a simple dialog, but in fact that is exactly what such things are for. Remember, five minutes start to finish...
One way to get the user's attention is to "disable" the regular UI and put a "sheet" or fake dialog over the top. In order to do this without calling an actual ask or answer dialog takes more effort but gives you much more control over the look... and it will transfer to mobile since this method doesn't require a separate stack to act as the modal dialog window. (I'm not defending this as necessarily being any sort of modern looking UI.)
1. Build a fake dialog. Place a group that has all the parts that you want... fields, button, background UI on the screen. (This group could be something you make ahead of time and hide or you can create it on the fly.) In the "Ok" button (actually you need something in all of however many buttons you use) have some code that will talk back to your main script by placing information in a global variable (Yes, I know there are "better" methods that don't require a global... don't hate ;- )
on mouseUp
global gMyDialogMessage -- globals need to be declared
put field "myCustomDialogField" into gMyDialogMessage -- puts what the user entered into the global
end mouseUp
or if it is a "Cancel" button you could put "Cancel" into gMyDialogMessage... (I would actually put something that the user wouldn't or couldn't enter, just to avoid confusion in case the user were to actually type "cancel" into the field "myCustomDialogField".)
2. Place an opaque black graphic with partial transparency (blendlevel of 70 perhaps) over the top of your usual UI. This will "disable" all the controls under it and cause the user to focus on the fake dialog group from step 1
3. Show the user the fake dialog group from step 1
4. In the code where the the "fake" dialog is called (where you would ordinarily call ask or answer) you can set up a repeat loop that checks the global variable you used in the fake dialog buttons. So instead of just calling ask or answer you will need to:
global gMyDialogMessage -- globals need to be declared
set the layer of graphic "myCustomDisableGraphic" to top -- make sure it is over the top
show graphic "myCustomDisableGraphic" -- make the normal UI appear disabled
set the layer of grp "myCustomDialog" to top -- make sure the fake dialog is on top of everything including graphic "myCustomDisableGraphic"
show grp "myCustomDialog"
put empty into gMyDialogMessage -- start with the variable empty
repeat until gMyDialogMessage is not empty -- wait for the user to click a button in the fake dialog
wait 20 millisec with messages -- don't lock up the app... allow the user to interact with the fake dialog
end repeat
-- here is where you hide or delete both the graphic that is covering the screen and the fake dialog group
-- use the global variable, gMyDialogMessage, to continue on as if you had used a regular ask or answer dialog
if gMyDialogMessage is... then
end if
This mobile-friendly method will allow you to call a fake custom "modal dialog" and have it communicate back without having to exit your original code... similar to the built-in modal dialogs, albeit more work. Thanks to Ken Ray for showing me how to do this (at the Atlantic City conference, I think.)
Elementary Software
...now with 20% less chalk dust!