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

Invalid combination of prototype JS validation classes #103

Closed
dfelton opened this issue Oct 12, 2015 · 3 comments
Closed

Invalid combination of prototype JS validation classes #103

dfelton opened this issue Oct 12, 2015 · 3 comments

Comments

@dfelton
Copy link
Contributor

dfelton commented Oct 12, 2015

The umc.xml file has validate-alphanum validate-code for the class names of the "Entity code singular" and "Entity code plural" fields (lines 168 and 177). Both these input fields are contained within the "Name settings" section of setting up a new entity. The combination of these two prototype validation classes does not allow for camel casing or usage of underscores. validate-alphanum would allow us to utilize camelCasing while validate-code would allow for us to use underscores.

img1

img2

I'm currently working on an update to the extension to add a custom validation class for use by UMC for these two fields. Prior to pushing the changes to my UMC's branch and creating a pull request I wanted to get your feedback on my approach to a solution here, regarding what to actually allow. I think one of the following two validation tests would be appropriate:

Validation.add('umc-validate-entity-code', 'Please use only letters (a-z or A-Z), numbers (0-9) or underscore(_) in this field, first character should be a lowercase letter.', function(v) {
    return Validation.get('IsEmpty').test(v) ||  /^[a-z]+[a-zA-Z0-9_]+$/.test(v)
});

img3

OR

Validation.add('umc-validate-entity-code', 'Please use only letters (a-z or A-Z) or numbers (0-9) in this field, first character should be a lowercase letter.', function(v) {
    return Validation.get('IsEmpty').test(v) ||  /^[a-z]+[a-zA-Z0-9]+$/.test(v)
});

img4

The only difference is that the first would allow for underscores, while the second would not. I feel the urge to go with the second option, as it more conforms to Zend's Coding Standard since underscores are only permitted as a prefix to protected/private class properties. However, doing some research it seems as though Zend is in the minority here for disallowing underscores in variable names (according to this Stack Overflow post).

Since this is your module, I figure I'd just ask. Do you have a preference here? I understand you've made efforts to conform the extension to Zend's coding standards so I suspect that'd be your preference.

Putting some thought into if this would create backwards compatibility issues for the community, I don't think there would be. UMC already doesn't allow for underscores in these two fields as it is; therefore existing modules created by UMC would still be valid.

Lastly, where would you put this snippit of JavaScript? My first inclination is to just throw it into the end of js/ultimate_modulecreator.js. But I notice that the file is entirely related to the definition of the UMC JavaScript object, so it may be appropriate to have a js/ultimate_modulecreator/prototype/validation.js file to store this.

@dfelton
Copy link
Contributor Author

dfelton commented Oct 12, 2015

Note: After reading through the comment thread for issue #101 I would like to also add an additional validation prototype validation class for the Namespace and Module Name. It would most likely be along the lines as follows:

Validation.add('umc-validate-class-name', 'Please use only letters (a-z or A-Z) or numbers (0-9) in this field, first character should be an uppercase letter.', function(v) {
    return Validation.get('IsEmpty').test(v) ||  /^[A-Z]+[a-zA-Z0-9]+$/.test(v)
});

With that said, it may indeed be more appropriate to add this JavaScript (along with the JS above) within my second recommendation of js/ultimate_modulecreator/prototype/validation.js. Will await your feedback though.

@tzyganu
Copy link
Owner

tzyganu commented Oct 13, 2015

@dfelton First of all I want to thank you for all the wonderful PRs you've done for this extension. All my respect and gratitude for making this better.
The validations you mentioned were top priority on my todo list, but I just didn't get around on starting them.
I'm not very good at regex so your ideas and your code couldn't come at a better moment.
I would go with the second approach on validating the entity code since underscores in the entity code would most probably screw up the file names generation.
Your code looks fine to me. Just one more addition. Can you please add the validation error messages to the jstranslate.xml file and in the language file also?

@tzyganu
Copy link
Owner

tzyganu commented Oct 27, 2015

@dfelton This should be implemented in version 1.9.6.0. Thanks for the regex.
Please take a look and see if it's OK.
Bonus: As a sign of gratitude for all you've done for the UMC (and what you will do) your name will remain forever in the "thank you wiki page" and in the code

@tzyganu tzyganu closed this as completed Oct 27, 2015
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