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

Add support for contentEditable tags #1418

Merged
merged 6 commits into from
Oct 29, 2015

Conversation

dorner
Copy link
Contributor

@dorner dorner commented Feb 26, 2015

Currently the validation library only works on classic form elements. However, there is no reason it can't work on rich text elements that have names and use contentEditable. This change adds support for these tags.

@staabm
Copy link
Member

staabm commented Feb 27, 2015

Please add a unit test and make the build pass again

@@ -606,7 +606,12 @@ $.extend( $.validator, {
return element.validity.badInput ? false : $element.val();
}

val = $element.val();
if (element.hasAttribute('contenteditable')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use double quotes to fix CS

@dorner
Copy link
Contributor Author

dorner commented Feb 27, 2015

Sorry! Total failure to read the contribution guidelines. X-X Should be fine now. Had to add one or two more lines because I forgot that I had some handling code in my own app which I've now moved to the plugin.

@staabm
Copy link
Member

staabm commented Feb 27, 2015

@dorner dont worry thanks for your contribution.

Could you have another look because the build is still failing..

@dorner
Copy link
Contributor Author

dorner commented Mar 2, 2015

Gak, forgot to run grunt after I fixed the tests -_- Everything should be fine now.

@@ -549,20 +549,26 @@ $.extend( $.validator, {

// select all valid inputs inside the form (no submit or reset buttons)
return $( this.currentForm )
.find( "input, select, textarea" )
.find( "input, select, textarea, [contenteditable]" )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jzaefferer not sure, but could this get a perf problem?

@jakobg
Copy link

jakobg commented May 5, 2015

Hi @dorner,

I've tried to use your code but get an "TypeError: e is undefined" by clicking into the contenteditable. Any suggestions?

Thanks,

Jakob

@dorner
Copy link
Contributor Author

dorner commented May 5, 2015

Haven't seen that personally... can you open Firebug / Chrome Tools and give me a stack trace?

@CameronJ
Copy link

Any updates on this? I'm looking for this feature as well

@staabm
Copy link
Member

staabm commented Oct 28, 2015

@CameronJ did you test the changes from this PR? Do those work for you in a x-browser manner?

I am fine with merging it, in case it gets rebased in case you confirm it works.

.not( ":submit, :reset, :image, [disabled]" )
.not( this.settings.ignore )
.filter( function() {
if ( !this.name && validator.settings.debug && window.console ) {
var name = this.name || $(this).attr("name"); // for contenteditable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use tabs instead of spaces. Also, please add one space after ( and one before ) in $(this).attr("name")

@dorner
Copy link
Contributor Author

dorner commented Oct 28, 2015

Whitespace issues should be fixed.

.not( ":submit, :reset, :image, [disabled]" )
.not( this.settings.ignore )
.filter( function() {
if ( !this.name && validator.settings.debug && window.console ) {
var name = this.name || $( this ).attr("name"); // for contenteditable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var name = this.name || $( this ).attr("name");
                                           
// one space after ( and one before )
// =>
var name = this.name || $( this ).attr( "name" );

(same as bellow)

@Arkni
Copy link
Member

Arkni commented Oct 28, 2015

Otherwise, it LGTM :)

The only thing needed after adjusting as per comments, is to rebase your branch on top of master (upstream)

Thanks :)

dorner and others added 5 commits October 28, 2015 13:40
Currently the validation library only works on classic form elements. However, there is no reason it can't work on rich text elements that have names and use contentEditable. This change adds support for these tags.
@dorner
Copy link
Contributor Author

dorner commented Oct 28, 2015

OK, think everything should be fine now. 8-)

@staabm
Copy link
Member

staabm commented Oct 28, 2015

@CameronJ does this patch work for you?

console.error( "%o has no name assigned", this );
}

// set form expando on contenteditable
if ( this.hasAttribute( "contenteditable" ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment that we use hasAttribute to support IE and mention the version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other way around - I mentioned above that hasAttribute is a clean way of checking but it does not support IE versions before 8. In my company we've dropped support of IE7 a while ago, not sure if you want me to comment on this or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, misread it. I am fine with not supporting IE7

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe hasAttribute isn't supported completely by IE8 either.
This may be better written as: $(this).is( "[contenteditible]" )

@CameronJ
Copy link

@staabm I have not tested this, I was just looking to see if there was an PR or feature request logged for this feature, and found this thread and realized it was a bit stagnant for awhile. LOVE jQuery Validate, and am about to integrate a different wysiwyg editor which only uses div with content editable and would like to avoid using a different validation method for just that one field. On this site though, I only need support for current browser versions and one prior, so my cross browser requirements are a lot less stringent than the majority of implementations. Let me know if you would like me to do some rudimentary testing on this anyway, even though it will cover a very limited set of browsers & versions.

@staabm
Copy link
Member

staabm commented Oct 28, 2015

@CameronJ would be great if you could test this PR so we have another pair of eyeballs checking things are working as expected

@dorner
Copy link
Contributor Author

dorner commented Oct 28, 2015

Fixed the whitespace issue again. -_-

@CameronJ
Copy link

Sorry guys, I didn't get a chance to look at this today. I will look at it tomorrow and verify the PR. Looking at the code that changed, I do not see anything that would be a problem at all for me...

But, Element.hasAttribute is only supported fully by IE9+, not IE8. I added this comment inline in 2 places above, where hasAttribute is being used.

Thanks for restarting this PR and helping get it merged!

@dorner
Copy link
Contributor Author

dorner commented Oct 29, 2015

Really? Everything I've seen says it is supported unless you're in "IE7 Standards mode". Just curious what your source is?

@CameronJ
Copy link

I was using W3Schools for my references, I have often found them to be accurate; however, if the MSDN page shows that it's supported in IE8, then it sounds like W3Schools may have gotten this one wrong.

staabm added a commit that referenced this pull request Oct 29, 2015
Add support for contentEditable tags
@staabm staabm merged commit 5d778ee into jquery-validation:master Oct 29, 2015
@CameronJ
Copy link

I have run the qunit tests on a couple different browsers and everything is passing and looking good. Also, I did a very rudimentary integration of this and everything seems to be working as expected.

@staabm
Copy link
Member

staabm commented Oct 29, 2015

@CameronJ great thx. The changes are already merged.

Thx @dorner for the PR and also @Arkni for reviewing it.

Looking forward for the next batch of PRs of you guys :-)

@dorner dorner deleted the content-editable branch October 30, 2015 15:08
@dorner
Copy link
Contributor Author

dorner commented Oct 30, 2015

Yay! 8D

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

Successfully merging this pull request may close these issues.

6 participants