javascriptoracle-databasevalidationcrmrightnow-crm

Form Validation for Custom Objects in Customer Portal


The more I delve into the CP documentation, the more I realize how much of my assumptions were turning out to be wrong. At the moment in the quest to understand the system efficiently, I'm looking to build a form consisting of only custom objects (Non-Incident/Non-Answer/Non-Contact) and then try and use that on the customer portal.

To keep things simple, all I'm trying to do is have a 2-field form (both textboxes) and a submit button as the front end. The following are the things which I'm trying to do:

I soon realized that I simply can't use the standard input/FormInput (to generate text boxes) widget for custom objects. I also found that I can't use the standard input/TextInput widget too. After some R&D, I finally managed to find a solution by creating a widget from scratch and adding appropriate HTML inside its view.

So far so good. My first step was taken care of. I was able to use

<rn:widget path="/custom/nl/custom_input" name="Packagename$Objectname.c$Fieldname" required = "true" />

in the form's view page.

The next step, Form Validation, is the point which is confusing me to no limits. I'm having trouble understanding the code given in the documentation and hence decided to make a thread about it here.

I came across this which unfortunately didn't help much. I also came across another thread (can't seem to find the URL) in which the OP had used a custom widget which was extending the input/TextInput widget and wanted to know how to apply validation to that textbox. The answer given was to override the onValidate function of input/TextInput and return false if error or return the event object if success.

So am I right in assuming that perhaps I can follow a similar approach? Since I'm using a new widget, is there a similar method which I can override and return true or false? And if yes, what would be the name of the function? Any help much appreciated.


Solution

  • I had figured it out through a series of trial and error methods. What I did was extend my custom input with Rightnow.Field inside its logic.js file.

    Custom.Widgets.nl.custom_input = RightNow.Field.extend({
        overrides: {            
            constructor: function() {               
                this.parent();
    
                /* Call a custom function on form submit */
                this.parentForm().on("submit", this.onValidate, this);
            }
        },
    

    The following functions were taken from the logic.js file of SiteInfo (A custom object sample code provided in the CP documentation) and included inside my input's logic.js file to complete the validation process.

    That automated the whole process and the validation was taken care of. Well, at least for the textboxes...