Form with tinyMCE textarea having html5 required attribute cannot submit - html

This is not a question, but an answer which I want to share with you. I've just spent over four hours tearing my hair out on something which turns out to be a bug in either TinyMCE or Firefox.
With TinyMCE loaded, if you specify the HTML5 required attribute on a textarea the form will just not submit in Firefox. No errors, nothing in Firebug, just a stubborn refusal to submit.
I don't know if this is a FF or a TinyMCE bug and don't really care. I just don't want other coders to go through the aggravation I've gone through these last hours.
To ask a question: Is this bug documented anywhere? Does anyone know?
If this is an inappropriate post for Stack Overflow, tell me and I'll delete it.

The problem is far from being a Firefox issue. Indeed Chrome and Opera ("old" opera before the "brain" was transplanted with Chrome's) and probably every other modern browser would give you the same headache.
With both Opera and Chrome, there's a flag insisting the field is a required one, (despite the fact that you have content in it). Chrome is nice enough to give you this error message in the console:
An invalid form control with name='<name of textarea>' is not focusable.
Not too surprising when you consider that TinyMCE actually creates an editable div container, hiding your original textarea. It is this hidden textarea (bearing a required attribute) that the browser is expecting you to provide a value for.
Over at Github, here: https://github.com/tinymce/tinymce/issues/2584, there is a suggested solution which goes like this:
// fix tinymce bug
if($this.is('[required]')){
options.oninit = function(editor){
$this.closest('form').bind('submit, invalid', function(){
editor.save();
});
}
}
I haven't tested this snippet personally, but studying it might be able to get you going, as long as you're able to drop it into the right place.

I realize this was asked 2 years ago, but I'm running into the same problem, so to answer your question:
I found the official bug report here: http://www.tinymce.com/develop/bugtracker_view.php?id=5671

My solution for this (which is related to WordPress TinyMCE setup):
jQuery( function ( $ ) {
$( '.smyles-add-required-attr' ).attr( 'required', 'required' );
tinymce.on( 'AddEditor', function ( e ) {
console.log( 'Added editor with id: ' + e.editor.id, e.editor );
var $editor = tinymce.get( e.editor.id );
$editor.on( "change", function (e){
$editor.save();
});
});
} );
The jQuery above adds the required flag (it can be done numerous other ways as well), and makes sure the text area is updated after being changed
To deal with issue of element not "focusable" just set opacity and height so you can remove display: none;
This CSS assumes you have added the class smyles-add-required-attr to editor when output using the editor_class (for WordPress wp_editor)
textarea[style*="display: none"].smyles-add-required-attr:invalid {
height: 0px !important;
opacity: 0 !important;
position: absolute !important;
display: flex !important;
margin-top: -75px;
}
This adds a red border around editor, assuming it's inside of fieldset in your form
.my-form fieldset:invalid .wp-editor-wrap {
border: 1px solid red;
}
One potential issue is that on page load the red border shows around fieldset, you can use fieldset:invalid:focus-within but beware it has limited browser support https://caniuse.com/#feat=css-focus-within

Related

CSS focus psuedo class, only on keyboard (tabbed) focus

It's a basic question really, but I can't find an answer. My CSS looks like this;
a:focus, button:focus{outline:3px solid #000;}
What I want is for the focus to only apply when the user tabs to those elements using the keyboard.
This is exactly how it works in Chrome, but in FF and IE the outline shows when the user clicks on the elements. Which isn't what I want.
Is Chrome in fact wrong? I'm trying to keep it simple and avoid Javascript is possible. How can I get the outline to show only when the user tabs around the page?
Browsers are IE8+, FF and Chrome only.
Thanks for any help!
Ok I know I said no JS if possible, but I don't wanna to spend any more time on this ... so for anyone interested this is what I did
$("a, button, select, input[type=submit], input[type=text]").keyup(function(){
$(this).addClass("focusOutline");
}).blur(function(){
$(this).removeClass("focusOutline");
});
Which does the job just fine. HTH someone sometime
Use :focus-visible. It's currently a W3C proposal for styling keyboard-only focus using CSS. Until major browsers support it, you can use this robust polyfill.
/* Remove outline for non-keyboard :focus */
*:focus:not(.focus-visible) {
outline: none;
}
/* Optional: Customize .focus-visible */
.focus-visible {
outline-color: lightgreen;
}
I also wrote a more detailed post just in case you need more info.
I did this a different way elsewhere, and thought I'd add it in here as an alternative solution for anyone who stumbles across it:
/**
* If user hits tab key then we add a class to <html> that lets us use
* additional styling hints to show focus etc.
*/
function detectTabKey() {
$(document).keydown(function(e) {
if (e.keyCode === 9) {
$('html').addClass('is-tab-user');
}
});
}

WP7 IE - CSS modal popup: Taps/Clicks go through overlay div and trigger links that should be invisible

I am making a HTML/CSS and jQuery-based file manager aimed at mobile devices. Part of it involves the use of CSS=based modal dialog boxes for various file operations (copy, delete etc.).
I achieve the modal dialog behaviour like this:
<div id="overlay">
<div id="modalBoxControls">[close]</div>
<div id="modalBox">
<div id="modalBoxContent"></div>
</div>
</div>
And the CSS is:
#overlay {
position: fixed;
left: 0px;
top: 0px;
width:100%;
height:100%;
text-align:center;
z-index: 1000;
background: ([semi-transparent png]);
display: none;
}
#modalBox {
width: 80%;
background-color: #fff;
margin: 0px auto;
opacity: 1;
}
I use jQuery to show and hide it by calling .fadeIn() and .fadeOut() on the overlay element.
So far so good - this works great in all the browsers on my dev machine.
However, when testing on my WP7 (Samsung Omnia 7), a rather bizarre thing happens. The modal dialog shows up fine, the page behind it is blacked out. But clicks (or taps) go through the #overlay and activate anything behind it, even though it totally covers up everything behind and it's z-index is 1000.
I also tested this with the well-known "Lightview" plugin from Nick Stakenburg (a well-tested and refined piece of code) and found the same behaviour on IE on WP7.
So it seems like this could be a bug with the browser itself.
Does anyone know any solution for this?
Edit - jsFiddle with example of problem
So, check this out in your WP7 device and see how the files can still be clicked even when there is an overlay over the top of them: http://jsfiddle.net/michaelbromley/CHU76/
If by "activate anything behind it" means input controls like text input then I had the same issue. To be honesty I don't know a good solution. My workaround was disabling input controls during popup is showed and then activating them back by removing disabled attribute. The problem seems not to be related to jqmobile, but supposed to be a general behavior.
OK, so it seems that there may be no "proper" solution to this problem (hey, 24 hours is a long time on SO!), so I have come up with my own hack solution:
I when the modal dialog box is opened, I simultaneously set the "visibility" CSS property of all the elements "behind" the overlay (i.e. links and anything else that would otherwise erroneously respond to taps/clicks) to "hidden" (by using jQuery's .css() function). This means that the page layout is not affected, and that there is now nothing there to be clicked on.
As I said, this is a bit of a hack and will not be suitable for everyone who runs into this problem. However, it works well for me.
Code in jsFiddle: http://jsfiddle.net/michaelbromley/CHU76/1/
Yes, this is clearly a bug in Window Phone 7 and it is not even fixed in Windows Phone 10.
I will report this bug to Microsoft and hopefully it will be fixed.

html elements unexpectedly invisible on first page load in chrome

I'm working on my new online portfolio at http://asbjorn.org/ny/, and I've come across the weirdest issue!
Every time you open the page for the first time, the next and previous buttons for the slideshow don't appear. If I open the inspector, they pop up immediately, and they also appear when reloading the page.
They're pretty standard html elements, not added dynamically, so I have NO clue as to why this happens! Of course I can't have the site visitors reload the page just to see them. :/
I really hope someone can help me! :)
update: seems like it's a chrome only issue. For me it happens consistently in chrome on both Win7 and OSX. A few of my friends also has the same issue (probably in chrome on osx)
So I'll take a stab at an answer. When I see the problem in Chrome 22, and I bring up the inspector, I note that the #previousLink and #nextLink divs have a width of 0 in the broken state. Try setting an explicit width for these in your CSS, or make the nested image use display: block.
#previousLink { width: 31px; }
#nextLink { width: 37px; }
or
#previousLink img,
#nextLink img { display: block; }
I think the combination of these inline items and your overflow: hidden rule are biting you. I think. This is a tricky bug!

Input field leaving artifacts from CSS3 transition (in Chrome 15)

http://jsfiddle.net/danielcgold/SYgzJ/
When you click on the input then go on blur, artifacts are left on the screen in Chrome 15. I first noticed this issue on a site i've been developing so I eliminated everything but just the input field and a button. When I remove the button, the transition happens just fine. Any ideas?
Add this CSS to your input field:
input {
-webkit-transform: translate3d(0,0,0)
}
This will force Chrome to use your GPU to do all the rendering which will solve the artifacts problem and make your animations smother.
This is a bug in Chrome's rendering of CSS transitions. But you can workaround it by forcing element "refresh" operation. Please note that you need to refresh not the input element, but it's parent, so the following code will help you:
$(document).ready(function(){
$('#test').blur(function(){
$(this).parent().addClass('repaint');
});
$('#test').focus(function(){
$(this).parent().removeClass('repaint');
});
});
And repaint class should have something related to parent's view, for example different color:
.repaint {
color: red;
}
But you may replace color with visibility or other view-related (but not important/visible for parent) attribute.
Here is jsfiddle to demonstrate the workaround
I had a similar problem with box shadow artifacts in Safari, and found adding -webkit-transform:scale(1); to the focus rule fixed the problem.
See http://jsfiddle.net/SYgzJ/48/ – it should work fine now.
As Cesar said, -webkit-transform: translate3d(0,0,0); will fix it, but it can affect text rendering too.

Internet explorer with tinymce creates box when clicked

I would like to make tinymce work in my CMS with IE but i stumbled over the following problem:
When i click into the editor i get a very ugly box which makes users unhappy.
It is not possible to select more than one paragraph.
I am sure there is a workaround or init setting for this.
Can anyone help me?
I found out the reason for this problem. It was a css setting:
p {
min-height : 18px;
}
After removal everything worked fine.
Edit: The following css setting had the same unwanted effect:
p {
width : 250px;
}
Helpfull link concerning the problem: http://www.satzansatz.de/cssd/onhavinglayout.html