iSeries EGL

All things EGL for the iSeries / i5 / Power System

Archive for the ‘EGL DojoTextField Validation’ Category

DojoTextField Validation

leave a comment »

How to Validate Values in a Text Field

Shown below is the screen segment allowing for the entry of a number which controls the number of records returned from a SQL statement.

Field to be validated

Shown below is the EGL code used to present the above segment into the browser page. The variable ‘recordSizeLimitField’ holds the instance of a DojoTextField that has been defined as an input-required field. If the field is left blank at the time the form is submitted the message declared with ‘inputRequiredMessage’ is presented.


    TextLabel9 TextLabel{ layoutData = new GridLayoutData{ row = 2, column = 1 }, text = "Limit results to " };
    recordSizeLimitLabel TextLabel{ layoutData = new GridLayoutData{ row = 2, column = 3 }, text = "records." };
    recordSizeLimitField DojoTextField { inputRequired=true, maxLength=4, inputRequiredMessage="Please supply a value for this field.", layoutData = new GridLayoutData{ row = 2, column = 2 } };

Fig.1 – The field and field label definition

Shown below is the EGL code used to define the Model, View and Controller (MVC) in addition to the name of the function used to validate the field.


    recordSizeLimitField_Model String { inputRequired=yes };
		recordSizeLimitField_Controller Controller { @MVC 
      { model=recordSizeLimitField.text, 
        view=recordSizeLimitField as Widget},
        validators = [recordSizeLimitField_Validator]
    };
    
    recordSizeLimitField_FormField FormField { 
      controller = recordSizeLimitField_Controller, 
      nameLabel = recordSizeLimitLabel
    };
	
    loggingViewerForm FormManager { 
    entries = [ recordSizeLimitField_FormField ]};

Fig.2 – The Model, View, Controller (MVC), FormField and FormManager

Shown below is the EGL code used to define the function ‘recordSizeLimitField_Validator’.


    function recordSizeLimitField_Validator(input String in) returns(String?)
    	
        if( !( input is numeric )  )
       	   InfoBus.publish("validate.field.relations", "ERROR");
           return("This value is not numeric. Please correct and retry");
        end
       
    end

Fig.3 – The validator function referenced by ‘recordSizeLimitField_Model’ in Fig.2

 

Behavior

When the field is left blank and the “Submit” button is selected the following is presented.

When the “!’ is selected, the message is presented.

When an invalid value is entered and the “Submit” button is selected the following is presented.

When the “!’ is selected, the following message is presented.

Advertisements

Written by iseriesadmin

June 19, 2012 at 1:45 pm