0

I need to validate my forms in LifeRay portlet. After some research I understands that LifeRay has 2 ways to validate form: using Alloy UI taglibs and using Alloy UI javascript library. And using taglibs it is the old way (please correct me if I'm wrong).

So I want to make validation using Alloy UI Javascript library. But how I can include it to portlet? As I understand the Alloy UI JS library is bundled with LifeRay since 6.x version. May be I need to specify <header-portlet-css> and <header-portlet-javascript>? Because it seems Alloy UI didn't included to each portlet automatically.

WelcomeTo
  • 19,843
  • 53
  • 170
  • 286

1 Answers1

3

This is a sample.

Insert in you portlet JSP the alloyui taglib with the right use attribute to have within the context the A.FormValidator object:

<aui:script use="aui-form-validator">

var validator = new A.FormValidator({
    boundingBox: form,
    rules: {
        '<portlet:namespace />emailAddress': {
            email: true
        },
        '<portlet:namespace />countryId': {
            required: true
        }
    },
    strings: {
        required: '<liferay-ui:message key="this-field-is-required" />'
    }
});

</aui:script>
Daniele Baggio
  • 2,157
  • 1
  • 14
  • 21
  • THanks, will try it now. But what is difference between using this `` (as suggested you) and this one: `YUI().use( 'aui-form-validator',` – WelcomeTo Oct 23 '13 at 13:01
  • Also I tried [this](http://alloyui.com/examples/form-validator/real-world/) example from `alloyui.com`, but CSS classes don't applied by default. Can you help me with setting up it? I use LifeRay 6.1.2. Thanks. – WelcomeTo Oct 23 '13 at 13:22
  • To go with js only you have to use `AUI().use( 'aui-form-validator',`. The two ways are quite similar. – Daniele Baggio Oct 23 '13 at 14:15
  • There's really not that much difference between using the taglib and the raw code, other than the taglib buffers all the code and pushes it to the end of the page. It works also better for compatibility. You have a good insight at http://stackoverflow.com/a/17464928/681838 – jbalsas Oct 24 '13 at 09:06
  • Thank you, but I encountered new problem with your solution, I created [new question](http://stackoverflow.com/questions/19570229/liferay-form-validation-using-alloy-ui) – WelcomeTo Oct 24 '13 at 15:53
  • @jbalsas please, review my new question too. This is the [link](http://stackoverflow.com/questions/19570229/liferay-form-validation-using-alloy-ui) – WelcomeTo Oct 24 '13 at 15:54