Extensibility
One of most looked onto features of a framework is Extensibility. One of the main aim of Ashera is Extensibility i.e. the ability to extend existing functionality in a cross platform way.
Ashera provides ability to extend existing functionality through factory registration. We can extend the following functionalities:
- Validation
- Filtering
- Add new attributes to existing widgets
- Add new native formatter
- Add a new widget
- Add a new image loader
- Add a decorator where in attribute is added to all widgets like Borderdecorator
- Mixing widget
- Widget overriding
These extensions are discussed in the future sections.
Adding a new validator
Ashera provides predefined validators which has been discussed in the previous section here.
In most cases this is sufficient. However Ashera provides framework to create validators in cross platform way.
The following are the steps to create new validator:
- Download a copy of https://github.com/AsheraCordova/Custom.git into the project folder. This project acts as a template for adding custom cross platform functionality.
- Install the plugin onto the project using command
cordova plugin add Custom
.
- Import the project into your favorite ide. e.g. eclipse
- Sample validator can be found in the project here
- After you create your new validator, you need to register it as follows
ValidatorFactory.register("lowercaseonly", new CustomValidator());
- Also given that the project is cordova plugin, you need to update plugin.xml and reinstall the plugin for any new functionality to take effect.
Example - Lowercase only validation
The following example validates if the text entered contains only lower case letters. If upper case letters are entered, validation fails.