Alpha DevCon 2018
Results 1 to 2 of 2

Thread: restrict user input on combobox without field rule

  1. #1
    Member
    Real Name
    Marco Gallardo
    Join Date
    Sep 2016
    Posts
    20

    Default restrict user input on combobox without field rule

    Ever make a comboBox and want to prevent the user from entering any values that aren't in your "user defined list" but don't want/need to make a field rule? this example code may get you there.

    just place this function on the combobox "canDepart" event.

    Code:
    FUNCTION restrictToDropDown AS L (fieldName as c = "" )
    	'for use when you specify "user defined" choices in a combobox and you want to force the user
    	'to pick from the list and not enter other values manually
    	
    	'pretty name if the actual field name is too cryptic for the user
    	if trim(fieldName) = "" then
    		fieldname = this.name()
    	end if
    	
    	choices = properties_enum(this.choice)
    
    	dim definedList as C = ""
    	for each item in choices
    		if "list" $ item then
    	 		definedList = definedList + trim(item) + crlf()
    		end if
    	next
    	
    	dim listOfValues as C = ""
    	for each item in definedList
    		listOfValues = listOfValues + trim(eval("this.choice."+item+".value")) + crlf() 
    	next
    	
    	if .not. word_exists(listOfValues,trim(this.value)) then
    		ui_beep()
    		msgbox("Incorrect value","Please select a valid choice from "+ fieldName +"'s drop down menu")
    		this.cancel()
    		this.Activate()
    	end if	
    	
    	restrictToDropDown = word_exists(listOfValues,trim(this.value))
    	
    END FUNCTION
    want to take it one step further and prevent the user from saving the form?

    1. define a "Layout Variable" on the form e.g. validValue = .t.
    2. on every combo box's canDepart pass the functions output to the variable
    Code:
    validValue = restricToDropDown()
    3. on the forms "canSave" create a Cancel Event using action script and specify this in the script's "Cancel event if this condition is true" box
    Code:
    .not.ValidValue
    it is spammy when the user tries to save, so its not perfect, but it gets the job done. of course if they are choosing values from the drop down they'll never see the warning messages anyway >:)

  2. #2
    Member
    Real Name
    Marco Gallardo
    Join Date
    Sep 2016
    Posts
    20

    Default Re: restrict user input on combobox without field rule

    Couldn't figure out how to edit my original post, but found a bug that needed fixing. Needed to allow empty strings as valid choice.
    Code:
    FUNCTION restrictToDropDown AS L (fieldName as c = "" )
    	'for use when you specify  "user defined" choices in a combobox and you want to force the user
    	'to pick from the list and not enter other values manually
    	
    	'pretty name if the actual field name is too cryptic for the user
    	if trim(fieldName) = "" then
    		fieldname = this.name()
    	end if
    	
    	choices = properties_enum(this.choice)
    
    	dim definedList as C = ""
    	for each item in choices
    		if "list" $ item then
    	 		definedList = definedList + trim(item) + crlf()
    		end if
    	next
    	
    	dim listOfValues as C = ""
    	for each item in definedList
    		listOfValues = listOfValues + trim(eval("this.choice."+item+".value")) + crlf() 
    	next
    	
    	if .not. word_exists(listOfValues,trim(this.value)) .and. trim(this.value) <> "" then
    		ui_beep()
    		msgbox("Incorrect value","Please select a valid choice from "+ fieldName +"'s drop down menu")
    		this.cancel()
    		this.Activate()
    	end if	
    	
    	restrictToDropDown = word_exists(listOfValues,trim(this.value))
    	
    END FUNCTION

Similar Threads

  1. User cannot scroll when touching a text input field in a mobile panel.
    By MichaelCarroll in forum Mobile & Browser Applications
    Replies: 2
    Last Post: 03-27-2017, 05:08 PM
  2. User input compare to field name.
    By Rbouchette in forum Alpha Five Version 9 - Desktop Applications
    Replies: 3
    Last Post: 07-12-2009, 06:16 AM
  3. User input in a calculated field
    By Bman1984 in forum Alpha Five Version 9 - Desktop Applications
    Replies: 2
    Last Post: 01-23-2009, 02:57 PM
  4. switch from calculated field rule to user entered
    By John Fringer in forum Alpha Five Version 6
    Replies: 3
    Last Post: 10-31-2005, 08:14 AM
  5. restrict character input
    By John Cunradi in forum Alpha Five Version 4
    Replies: 6
    Last Post: 02-24-2001, 06:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •