Showing a Red Asterisk on a Rich Text Box

Q: How do I get the red asterisk to show on a Rich Text Box? There isn’t a checkbox for “Cannot be blank” on this type of control!

 

A: Easy - add a declarative data validation rule for the condition where the field bound to the Rich Text Box “is blank”. To get started, display the control’s properties dialog box and then click Data Validation.

 

So now you’re wondering – why isn’t there a simple checkbox for that?

 

Behind the scenes, the “cannot be blank” checkbox actually maps to a change in the schema, rather than a declarative validation rule. For strings we add a length restriction, but for other types it sets nillable="true" (can be blank) or nillable="false" (cannot be blank).

 

This explains why the checkbox is enabled when using a schema you’re creating in InfoPath and disabled when using a fixed schema from an external source. Since the schema we use for rich text (XHTML) nodes is a complex type the nillable approach doesn’t apply.

 

So why does a declarative validation rule cause a red star to appear? When the form is running, the validation display semantics don’t distinguish between schema validation, declarative validation, and even code validation if you use an OnValidate event handler and/or add to the Errors collection. The logic for the validation display is:

 

            if( node fails validation )

            {

                        if( string value of node is blank )

                        {

                                    show red star

                        }

                        else

                        {

                                    show red border

                        }

            }