New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow support for input element names with a period (or any other CSS reserved char) #17

Closed
anadimisra opened this Issue Oct 20, 2012 · 2 comments

Comments

Projects
None yet
2 participants
@anadimisra

anadimisra commented Oct 20, 2012

When using the script in a spring based application which might have nested objects as form fields; we have to use the notation as follows

        <spring:bind path="demographicInfo.gender">
          <c:forEach var="gender" items="${genderList}">
            <li><label for=""><input name="demographicInfo.gender" type="radio" class="required" value="${gender}">${gender.gender}</input></label></li>
          </c:forEach>
        </spring:bind>

this currently fails for the validation plugin required method

        if (field.is(':radio')) {
            name = field.attr('name');
            if ($("input[name=" + name + "]:checked").length) {
                return true;
            }
            return i18n('req_radio', caption);
        }
        if (field.is(':checkbox')) {
            name = field.attr('name');
            if (field.is(":checked")) {
                return true;
            }
            return i18n('req_checkbox', caption);

I changed the method to add this snippet

        var name;
        if (field.is(':radio')) {
            var rawName = field.attr('name');
            if (~rawName.indexOf('.')) {
                console.log("escaping . chanracter");
                name = rawName.replace(".", "\\.");
                console.log(name);
            } else
                name = rawName;
            if ($("input[name=" + name + "]:checked").length) {
                return true;
            }
            return i18n('req_radio', caption);
        }
        if (field.is(':checkbox')) {
            if (field.is(":checked")) {
                return true;
            }
            return i18n('req_checkbox', caption);
        }

Not sure if this is the best way to do it; but this support should be there IMHO. Also the expression name = field.attr('name') is unnecessary in the if block for checkbox.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Apr 1, 2013

Hi @anadimisra - I'm currently doing some refactoring in the JavaScript for this project. I was just about to put together a unit test for this particular issue. Thanks for supplying code! I really appreciate it.

Just to clarify - the issue is from the css selector being built as "input[name=" + name + "]:checked" where the name isn't being escaped - correct?

ghost commented Apr 1, 2013

Hi @anadimisra - I'm currently doing some refactoring in the JavaScript for this project. I was just about to put together a unit test for this particular issue. Thanks for supplying code! I really appreciate it.

Just to clarify - the issue is from the css selector being built as "input[name=" + name + "]:checked" where the name isn't being escaped - correct?

@anadimisra

This comment has been minimized.

Show comment
Hide comment
@anadimisra

anadimisra Apr 1, 2013

Hi! Craig,

Yes that's what the issue is about escaping special chars if they are found
in the name.

BR/
Anadi Misra

On Mon, Apr 1, 2013 at 8:38 AM, Craig Davis notifications@github.comwrote:

Hi @anadimisra https://github.com/anadimisra - I'm currently doing some
refactoring in the JavaScript for this project. I was just about to put
together a unit test for this particular issue. Thanks for supplying code!
I really appreciate it.

Just to clarify - the issue is from the css selector being built as "input[name="

  • name + "]:checked" where the name isn't being escaped - correct?


Reply to this email directly or view it on GitHubhttps://github.com/draganbabic/uni-form/issues/17#issuecomment-15702759
.

anadimisra commented Apr 1, 2013

Hi! Craig,

Yes that's what the issue is about escaping special chars if they are found
in the name.

BR/
Anadi Misra

On Mon, Apr 1, 2013 at 8:38 AM, Craig Davis notifications@github.comwrote:

Hi @anadimisra https://github.com/anadimisra - I'm currently doing some
refactoring in the JavaScript for this project. I was just about to put
together a unit test for this particular issue. Thanks for supplying code!
I really appreciate it.

Just to clarify - the issue is from the css selector being built as "input[name="

  • name + "]:checked" where the name isn't being escaped - correct?


Reply to this email directly or view it on GitHubhttps://github.com/draganbabic/uni-form/issues/17#issuecomment-15702759
.

@anadimisra anadimisra closed this Jun 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment