Skip to content
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

Move validation from JavaScript to JSP #196

Closed
pathawks opened this issue Oct 2, 2018 · 2 comments
Closed

Move validation from JavaScript to JSP #196

pathawks opened this issue Oct 2, 2018 · 2 comments
Assignees

Comments

@pathawks
Copy link
Member

pathawks commented Oct 2, 2018

Instead of hardcoding these regex validations in JavaScript, we should embed them in our JSP forms referencing the constants in R.java. This way, we are not repeating the same expression in multiple places in our code, and updating the expression in one place will update it everywhere.

/**
* Returns the regular expression used to validate primitive names
*/
function getPrimNameRegex() {
return "^[\\w\\-\\.\\+\\^\\s]+$";
}

public static final String PRIMITIVE_NAME_PATTERN="^[\\w\\-\\. \\+\\^=,!?:$%#@]+$";

@Swisty
Copy link
Contributor

Swisty commented Oct 17, 2018

So I've been struggling with this for the last week, and maybe putting something here is the best way to try to solve the issues I'm running into.

I've tried to get the "pattern" attribute into the JavaScript with the .attr("") thing in the validate code, and as far as I can tell it's successful at getting that string into the JavaScript (I can tell it to output that string to an alert and it does just fine). However, when I try to test the user input against the regex made with the string, it's not getting the regex correct. The most common behavior I've seen is it only thinking "&" is an invalid character and accepting everything else.

When I hard-code the original JavaScript regex (the one we want to replace) directly into the code in job.js, it works perfectly fine. When I move that regex out into the JSP form into the attribute, however, it stops working completely.

Is there a way to circumvent this problem completely by just having the HTML check the pattern and get that result into the JavaScript somehow for feedback to the user? The "pattern" attribute is supposed to do this, but so far as I can tell the only way to check whether HTML input is valid is check it against everything we specify in the HTML, at which point the JavaScript won't be able to tell what's wrong with the input and would have to give a super vague feedback to the user about an invalid entry.

@pathawks
Copy link
Member Author

I think input.validity should give us a ValidityState object which would (hopefully) provide some insight into exactly why the input does not validate; is this not the case?

Did you push some commits that I can look at to see why the regex does not work when it comes from the JSP? I wonder if we need to escape ampersands before outputting them; maybe I can help with this, if I can see your code.

Maybe open a pull request and prefix the title with WIP:. This will let everybody know that it is a Work In Progress, and GitHub will not allow merging the PR until the title is changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants