Validating a phone number question that is an optional field

(ferdinand) #1

image

I have a question in my form that asks for a phone number as illustrated on the picture above. It’s an optional field, so it’s not required. I have included a validation rule. When I click on the green arrow to complete the form, it says : ‘There are errors in this form’s answers. These must be corrected before the form can be submitted.’ I Think it’s the validation condition that causes this to appear.

If I clear the validation condition, they may enter an incorrect phone number. Is there a way around?

thanks in advance

(Clayton Sims) #2

Hi,

You are correct that all questions with validation conditions must have their conditions met for forms to be completed/submitted. Can you clarify the behavior you are expecting in this case or attempting to implement?

-Clayton

(ferdinand) #3

Hi, Clayton.

I have a phone number question with a validation condition set and it is not a required field. it does not allow me to submit the form unless I fill this field. As an optional field, how can I skip it though is has a validation condition?

(Clayton Sims) #4

As the field is not required, you should be able to complete the form if there is no data in it. In your example you’ve entered text (“258”) into the field.

Does the form also not allow you to complete if the field is empty?

-Clayton

(ferdinand) #5

Hi, Clayton.

I have put 258 as a default value. this is a country code. the form allows me to complete if I remove the validation condition.from this phone number question.

(Ethan Soergel) #6

Hi Ferdinand,

If your question has a validation condition, CommCare will not allow the user to proceed if that validation condition is not met. If the question is not required, then a blank response will also be accepted.

One solution here would be to modify your validation condition to consider “258” a valid response. For instance, add “or . = 258” to your validation condition.

You could also remove the default value and use the validation condition to make sure phone numbers begin with 258.

(ferdinand) #7

Thank, you, Ethan for your help.