Disable/Hide Cancel button in inputbox

Is it possible to hide/disable cancel button in ui.inputbox.

1 Like

If you are talking about UI#inputbox class_method
then the answer is: NO.

1 Like

I am currently using UI.inputbox. So Do I need to replace it with UI.messagebox. Will it accept user input(dropdown) ?

The UI#messagebox-class_method does not have input fields.


Perhaps you can writhe a code If the user cancel the dialog (false is returned) you will relaunch the same imputbox again… (it is not that elegant… :blush:)

Or you can use UI::HtmlDialog class to writhe your own “inputbox” method.
(BTW. here is a template: Define the width of a inputbox - #6 by tt_su )

How can I get the reference to the Cancel button so that I can do some workaround by hiding/disabling it.
Or Even relaunching the inputbox once when if the user selects the cancel button.

No way to do it.

e.g. something like this…

def launch_questions
  prompts = ["What is your Name?", "What is your Age?", "Gender"]
  defaults = ["Enter name", "", "Male"]
  list = ["", "", "Male|Female"]
  input = UI.inputbox(prompts, defaults, list, "Tell me about yourself.")
end

def be_sure_to_answer
  answer = launch_questions
  if answer
    p "Answered"
    p answer
    #do what else you want with the "answer"
  else
    p "launch again"
    be_sure_to_answer
  end
end
be_sure_to_answer

1 Like

Can I ask for you reason to want to disable/hide the cancel button?

2 Likes

also forcing the user into a cycle they cannot escape from, is very bad UI design.

Your code should assume the user wants to cancel the task if they cancel the inputbox dialog.

def request_answers
  answers = launch_questions
  return nil unless answers
  puts "Answered:"
  puts answers.inspect
  # Continue task with the "answers" given:
  return answers
end

def nifty_command
  answers = request_answers()
  if answers
    name, age, gender = answers
    # continue task ...
  else # was falsey instead of an array
    # bail out gracefully - user cancelled
  end
end
1 Like

I have replaced inputbox with messagebox(MB_OK - Contains an OK button). But when the user closes the message window or even if he selects OK, the return value is same(1). We cant distinguish the user selection.

input = UI.messagebox “Text goes here”, MB_OK

The input value returns 1, even if he selects OK or closes the window.
Need to restrict the user closing the messagebox and bypassing it.

I don’t understand how a messagebox works as a replacement for an inputbox. They serve two different purposes.

When you say “closes”, do you mean the titlebar button of the dialog? Not the Cancel button? Because pressing Cancel on either dialog yield a predictable result.

Can you elaborate on what you are prompting the user for? What is the user scenario we’re dealing with here?

image
Close button at the right hand side of title bar.

I can kind of understand that Close in an OK only messagebox returning MB_OK wouldn’t be exactly expected, but that’s a system dialog, so the behaviour of pressing the close button would be consistent with with apps. I still wondering why you want/need to eliminate that close button?

In your original question you talked about UI.inputbox, that will return false when the user presses Cancel or the titlebar button. In this case the behaviour is consistent and without confusion. What’s the issue here?

The cancel button shouldn’t be removed. The user can start doing an action and then change their mind and realize they want to do something else. This is why there is a cancel button in the first place.

For the record, not all users are "he"s.

:roll_eyes:

image

That is expected. An OK message box is simply to display a message. OK and Close is effectively saying “I read the message now.” If you want a dialog that is cancelable use MB_OKCANCEL. Then you will get a IDCANCEL (2) result when the user cancels or or closes the message box. Alternately if you want to force the user to answer a question (IOW you can’t cancel), you use MB_YESNO. In such a case the close button is disabled and the user is forced to answer the question.

3 Likes