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!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
Samuele
- Posts: 282
- Joined: Mon Oct 11, 2021 7:05 pm
Post
by Samuele » Sun Nov 14, 2021 3:06 pm
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
Code: Select all
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
thanks!
Samuele.
-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10045
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Sun Nov 14, 2021 3:28 pm
Does something so important to your app need to be presented in a separate modal window?
Could the input field be present in the card, where you have total control over how the user interacts with it?
Modal dialog prompts were common in the early days of GUI computing, but most modern layouts put input forms more directly in the usage context.
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10317
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Sun Nov 14, 2021 3:36 pm
You can always roll your own dialog. Should take about five minutes. Do you need help with this?
Craig
-
Klaus
- Posts: 14194
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Sun Nov 14, 2021 5:17 pm
Samuele wrote: ↑Sun Nov 14, 2021 3:06 pm
Sorry, this (break in an IF THEN clause?) does not make sense.
What is it supposed to do?
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10317
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Sun Nov 14, 2021 6:33 pm
Klaus.
I saw that as well. Using "break" like that does not throw an error. I think the OP just wanted to exit, as if he had:
@Samuele. You do not need any of that. In fact you simply could have:
Code: Select all
if field "UserName" is empty then
ask "Enter username:"
put it into _guserName
put _guserName into field "UserName"
end if
See? If the conditional is not met, nothing happens anyway. This may be less readable, though, and nobody should criticize for readability.
Craig
-
Klaus
- Posts: 14194
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Sun Nov 14, 2021 6:57 pm
What Craid said!
If you really want to hide the CANCEL button, you could use this workaround:
Code: Select all
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....

-
Samuele
- Posts: 282
- Joined: Mon Oct 11, 2021 7:05 pm
Post
by Samuele » Sun Nov 14, 2021 10:26 pm
thanks!
like this?
Code: Select all
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
Samuele.
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10317
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Mon Nov 15, 2021 2:02 am
What Klaus said.
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.
Craig
-
Klaus
- Posts: 14194
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Mon Nov 15, 2021 10:07 am
Samuele wrote: ↑Sun Nov 14, 2021 10:26 pm
thanks!
like this?
Code: Select all
on AskName
if field "UserName" is empty then
...
end AskName
If it works, yes.
Hint:
This will not work on the mobile platform, since the ASK and ANSWER Dialogs are "borrowed" from the underlying OS there!
-
Samuele
- Posts: 282
- Joined: Mon Oct 11, 2021 7:05 pm
Post
by Samuele » Mon Nov 15, 2021 5:12 pm
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.
-
Klaus
- Posts: 14194
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Mon Nov 15, 2021 5:56 pm
Samuele wrote: ↑Mon Nov 15, 2021 5:12 pm
i 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.

-
jacque
- VIP Livecode Opensource Backer

- Posts: 7391
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Mon Nov 15, 2021 6:49 pm
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
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10317
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Mon Nov 15, 2021 7:03 pm
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...
Craig
-
scott_morrow
- VIP Livecode Opensource Backer

- Posts: 38
- Joined: Tue Jun 27, 2006 8:35 pm
-
Contact:
Post
by scott_morrow » Wed Nov 17, 2021 3:24 am
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!