Are you using CP2 or CP3 and which version of RightNow? I'll work with the assumption that it's CP2 here.
You're question is almost two part: 1) which widget can I use, and 2) how do I extend validation?
Since it sounds like you just want to use required
and validate_on_blur
standard widget attributes, then I think your first approach is better. You should be able to achieve what you have described with out-of-the-box functionality.
Using Standard Widgets
Try using a standard widget again using dot notation to access the field; similar to the approach in ROQL:
<rn:widget path="input/FormInput" name="Packagename.Objectname.Fieldname" required = "true" />
Custom objects do not have custom fields since the object itself is custom. So, there is no c$
prefix to access a field on a custom object. That notation only applies to custom fields on standard objects.
Also, of note, the FormInput
widget is just a wrapper for the other input widgets, including TextInput
.
Creating Widget Validation
If you want to use your custom widget, then you would need to override the appropriate methods in your logic.js
file as you mentioned. Depending on how you created the custom widget, onValidate, or whatever your validation method is, may not actually be a method in that file yet; you have to create it. In that case, you need to setup an event listener for your text field and then perform an action on the event. If you want to use blur, it would be something like the following (which is basically what the standard input widgets do)
RightNow.Widget.MyWidget = function(data, instanceID) {
//Setup widget data
this._inputField = document.getElementById("rn_" + this.instanceID + "_" + this.data.js.name);
YAHOO.util.Event.addListener(this._inputField, "blur", this._blurValidate, null, this);
}
RightNow.Widget.TextInput.prototype = {
_blurValidate: function()
{
//validate your field data
}
}
The CP3 approach is a bit different, especially since there is robust custom widget inheritance. So, if you are using CP3 and you still want to go the custom widget route, then check back.
Also, all of the standard widget code should be exposed to you via the src folder in WebDAV. If you have access to WebDAV through your profile, which you should since you are developing CP, then you can review how the standard widgets work and apply the same principles to your code.