Disable a Button Until All Required Fields are Filled In - Greg Collins
in

InfoPath Dev

This Blog

Syndication

Greg Collins

Disable a Button Until All Required Fields are Filled In

You might have a button in your form—such as a submit button—that you want to prevent the user from being able to click until all required form fields are filled in. This can be done using conditional formatting. The complexity of the conditional formatting depends on your form.

In this task we will create a simple form with a submit button. We will add conditional formatting to disable the button until all required form fields are filled in. Let’s start by designing a new blank form.

Create the schema:

  1. Open the Data Source task pane.
  2. Add a Text Field named Name, which cannot be blank.
  3. Add two Text Fields named Address, and Phone.
  4. Add a Text Field named Email, which cannot be blank.
  5. Add a Rich Text Field named Comments.

Add custom data validation to require that the rich text field cannot be blank:

Since we cannot specify in the data source that the rich text field cannot be blank, we must do this manually with custom data validation. Rich text fields work differently than plain text fields—you cannot simply check whether a rich text field “is blank” because this will not always produce accurate results.

  1. In the Data Source task pane, double-click Comments.
  2. On the Validation And Event Handlers tab of the Field Or Group Properties dialog box, click Add.
  3. Select The Expression from the first drop-down list, and then type the following expression:

not(.//node())

  1. Type Cannot be blank for the ScreenTip (as shown in Figure 1), and then click OK twice.


Figure 1. Custom validation requiring that a rich text field cannot be blank.

Design the view:

  1. Right-click myFields, and then choose Controls In Layout Table.
  2. From the Controls task pane, insert a Button into the view.
  3. Double-click the button.
  4. On the General tab of the Button Properties dialog box, change the label to Submit, and then change the ID to btnSubmit.
  5. Click Rules, and then click Add.
  6. Name the rule Submit, and then click Add Action.
  7. Select Show A Dialog Box Message from the Action drop-down list.
  8. Type Form Submitted for the message, and then click OK three times.

Add conditional formatting to disable the button:

  1. On the Display tab of the Button Properties dialog box, click Conditional Formatting, and then click Add.
  2. Select Name from the first drop-down list, select Is Blank from the second drop-down list, click And, and then select Or in place of And.
  3. Select Email from the first drop-down list, select Is Blank from the second drop-down list, click And, and then select Or in place of And.
  4. Select The Expression from the first drop-down list, and then type the following expression:

not(my:Comments//node())

  1. Select the Disable This Control check box (as shown in Figure 2), and then click OK three times.


Figure 2. The conditions required to disable the button.

Try it:

When you first preview the form you will find that the Name, Email and Comments fields are all marked with a red asterisks, indicating that they are required fields; you will also find that the Submit button is disabled. When you fill in the required fields the Submit button becomes enabled, allowing you to then submit the form. Figure 3 shows the form before and after the required fields are filled in.


Figure 3. The submit button is disabled until all required fields are filled in.

©2005 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

Comments

 

IanBuckland said:

I have many mandatory fields and I need to set states on a number of controls eg disable submit button / show hide message (since i am using webforms and therefore can't use dialogs). To manaage this I have created a true/false field called validationcheck that contains all the validation rules for the form. It ends up true if the validation passes. I trigger an update of validationcheck using rules at each control that need to be validated. Set it to true if contents ok and otherwise false.

Once the validationCheck field is working you only need to check this field.

Seems like a bit of effort and I suspect you could do this you could do this programmatically alot easier

September 22, 2009 5:31 PM
 

Disable Submit Button until all fields have data (PHP) [closed] | Search RounD said:

Pingback from  Disable Submit Button until all fields have data (PHP) [closed] | Search RounD

February 28, 2014 7:39 AM
 

empire z hack said:

Disable a Button Until All Required Fields are Filled In - Greg Collins

September 13, 2014 5:17 PM
 

human.gorodok.net said:

Disable a Button Until All Required Fields are Filled In - Greg Collins

September 18, 2014 2:31 AM
 

http://www.ww.sksplus.comww.sksplus.com/?a%5B%5D=%3Ca+href%3Dhttp%3A%2F%2Fconfidencegames.com%2Fsims-4-cheats%2F%3ESims+4+Cheats%3C%2Fa%3E said:

Disable a Button Until All Required Fields are Filled In - Greg Collins

September 18, 2014 4:06 AM
 

Globlins Cheats said:

Disable a Button Until All Required Fields are Filled In - Greg Collins

September 18, 2014 4:52 AM
 

www.janter.co.nz said:

Disable a Button Until All Required Fields are Filled In - Greg Collins

September 19, 2014 2:02 AM
 

Sims 4 iPhone Hack said:

Disable a Button Until All Required Fields are Filled In - Greg Collins

September 19, 2014 6:52 AM
Copyright © 2003-2012 Qdabra Software. All rights reserved.
View our Terms of Use.