3.2.0

Extending Controls

Hi folks,

I'm pretty new to AW (just bought it yesterday actually) so hopefully someone can point me in the right direction here...

I'd like to extend some of the AW widgets (like Input for example) to support some extra properties. e.g if I've got something like this:

My = {};
   My.UI = {};
   My.UI.Input = AW.UI.Input.subclass();
   My.UI.Input.create = function() {
      var obj = this.prototype;
   }


And I wanted a "required" property I could just do this:

My = {};
   My.UI = {};
   My.UI.Input = AW.UI.Input.subclass();
   My.UI.Input.create = function() {
      var obj = this.prototype;
      obj.required = false;
   }

   var myObj = new My.UI.Input();
   var req = myObj.required;


But is that the best (i.e. proper ;) way to do it? I'd like to do something like:

var myObj = new My.UI.Input();
      var req = myObj.getControlRequired();
      myObj.setControlRequired( true );


and so on. I think it's got something to with Models but I'm not sure (and my eyes are aching from looking at the source code!)

Any advice?

Thanks

Carl
Carl P
June 27,
Models are just groups of related properties :-)

In this case you would use the model called 'control' and property 'required'. The property is created (defined) with the call to define<ModelName>Property(name, defaultValue) -

obj.defineControlProperty("required", false);


The second argument (defaultValue) is optional.

This call will add

obj._controlRequired = false; // set default value
obj.getControlRequired = function(){...} // create getter method
obj.setControlRequired = function(){...} // create setter method


The method setControlRequired() will trigger two events. Before assignment - onControlRequiredChanging, and after assignment - onControlRequiredChanged. It is possible to cancel (prevent) assignment returning nonzero error code from onControlRequiredChanging event handler (useful for input validation etc.).
Alex (ActiveWidgets)
June 27,
Brilliant - thanks Alex!

Cheers

C
Carl P
June 27,

This topic is archived.

See also:


Back to support forum