简体   繁体   English

Liferay 6.2表单验证问题

[英]Liferay 6.2 Form Validation Problems

I've been trying to adapt the validator from this example in a LR 6.2 GA6 Portlet. 我一直在尝试根据LR 6.2 GA6 Portlet中的示例修改验证器。 However, I can't get it to work. 但是,我无法使其正常工作。 Curiously the validator-tag isn't working as well. 奇怪的是,验证者标签不能正常工作。
This is the form I've been using 这是我一直在使用的表格

<aui:form name="<portlet:namespace />address" action="<%=doSmthURL %>" id="fm">
<aui:container>
    ...
    <aui:row>
        <aui:col>
            <aui:input name="conditions1" label="text" type="checkbox" id="conditions1">
            </aui:input>
        </aui:col>
    </aui:row>
    <aui:row>
        <aui:col>
            <aui:input name="conditions2" label="conditions2" type="checkbox" id="conditions2"/>
        </aui:col>
    </aui:row>
</aui:container>
<aui:button-row>
    <aui:button type="cancel" value="Back"></aui:button>
    <aui:button type="submit" value="Finish"></aui:button>
</aui:button-row></aui:form>

And this is the Aui:Script part 这是Aui:Script部分

<aui:script>
var rules = {
        conditions1:{
            required:true
        },
        conditions2:{
            required:true
        }
}
var fieldStrings = {
        conditions1:{
            required:"Bitte nimm die allgemeinen Geschäftbedingungen an"
        },
        conditions2:{
            required:"Bitte nimm die allgemeinen Geschäftbedingungen an"
        }
}
AUI().use(
        'aui-form-validator',
        function(A) {
           new A.FormValidator(
             {
              boundingBox: "#fm",
              fieldStrings: fieldStrings,
              rules: rules,
              showAllMessages: true
             }
           )
        }
);

I am not sure why it isn't working. 我不确定为什么它不起作用。 Since using a validator tag isn't doing anything as well maybe it is a problem with javascript excecution as a whole. 由于使用验证器标签并不能很好地完成任何事情,因此这可能是整个javascript执行的问题。

I hope someone can help me. 我希望有一个人可以帮助我。

Kind regards, JSM 亲切的问候,JSM

Sorry, that documentation is confusing, and needs to be updated. 抱歉,该文档令人困惑,需要更新。

If you are able, I'd suggest using the <aui:validator> inside the <aui:input> . 如果可以,我建议在<aui:input>内使用<aui:validator> <aui:input>

<aui:input name="conditions1" label="text" type="checkbox" id="conditions1">
    <aui:validator name="required" errorMessage="Bitte nimm die allgemeinen Geschäftbedingungen an" />
</aui:input>

This way Portal is handling all the necessary JS. 这样Portal就可以处理所有必要的JS。

If you can't use <aui:validator , I'd suggest using Liferay.Form to access the Form Validator attached to the form. 如果您不能使用<aui:validator ,我建议您使用Liferay.Form来访问附加在表单上的Form Validator。 Because currently, you're attaching an additional one, which may conflict. 因为当前,您要附加一个,可能会发生冲突。

<aui:script use="liferay-form">
    var form = Liferay.Form.get('<portlet:namespace />fm');

    var oldFieldRules = form.get('fieldRules');

    var newFieldRules = [
        {
            body: function (val, fieldNode, ruleValue) {
                return (val !== '2');
            },
            custom: true,
            errorMessage: 'must-not-equal-2',
            fieldName: 'fooInput',
            validatorName: 'custom_fooInput'
        },
        {
            fieldName: 'fooInput',
            validatorName: 'number'
        }
    ];

    var fieldRules = oldFieldRules.concat(newFieldRules);

    form.set('fieldRules', fieldRules);
</aui:script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM