How to select tinyMCE textarea when pressing tab key? - tinymce

Hello
I got similar to that code
<form method="post" action="/" name="form" autocomplete="off">
<input type="text" name="title" />
<textarea name="body"></textarea>
<input type="text" name="tags" />
<input type="submit" name="submit" value="Send" />
</form>
Where the "textarea" is tinyMCE... problem comes when I try to move selection through input and textarea items.
When the page is loaded it focus input[name=text] but when I press Tab key it select input[name=tags] instead textarea[name=body] (which is next)
Can you assist me with that issue ?

This is impossible with conventional tab indexes as TinyMCE actually hides the <textarea> and creates an <iframe> with the editor in it. You could make a work around by forcing focus on the editor in the blur event of the previous element in javascript, here is ajQuery snipped of the top of my head:
$('#prev-input').blur(function(){
tinyMCE.get('textarea').focus();
});
Then as soon as the user leaves the previous input focus would jump to the TinyMCE editor, you could possibly add a blur() method as well to got to the next element.

I resolved this with adding 'tabfocus' to plugins and then add tabfocus_elements : ":prev,:next"
http://tinymce.moxiecode.com/wiki.php/Plugin:tabfocus
http://tinymce.moxiecode.com/wiki.php/tabfocus_elements

There is a plugin solved it
http://sourceforge.net/tracker/index.php?func=detail&aid=1657397&group_id=103281&atid=738747
I known it from TinyMCE forum
http://tinymce.moxiecode.com/forum/viewtopic.php?id=813

I needed a custom tabbing order from another element on the page. The code I used to resolve this in IE11 was
var button = $('#btn-id');
button.on('keydown', function (e) {
if ((e.which === 9 && !e.shiftKey)) {
e.preventDefault();
$(tinyMCE.get()[0].contentWindow).focus();
}
});
Be aware that the above code will only work if you've only got one editor on the page. Otherwise you'll have to cycle through the array returned by tinyMCE.get() to find the correct editor to set focus to.

I found out that the focus event is being triggered but focussing in the element (container) didn't work all the time.
In my case I tabbed from editor 1 - 4 and when I shift+tab I lost focus on the instance.
To fix this I added the following to the setup event of tinyMCE
setup: function(editor) {
editor.on("focus", function(e) {
e.target.editorContainer.scrollIntoView();
});
}

Related

jquery ajax popup and return selected checkbox inside pop up form

Seems like a common question but could not find on this site. Must be due to my lack of experience in jquery or ajax.
I have a form like this:
<form id="form1">
+Add Item
</form>
when the person clicks "+Add Item" it pops up a new page which allows him to navigate and click the desired checkbox. Then it should insert in the above form something like:
<input type="hidden" name="item1_id" value="4">Item 1<br>
where value="4" would be the id of the checkbox checked.
any help would be greatly appreciated.
Don't use an anchor tag. Instead, create a div container for your pop up, which you can load dynamically:
$('#container').load('add-item.php');
Then add a listener to your item buttons append the result in your form:
$("#item_1").click(function() {
var $newinput = $("<input type='hidden' />");
$newinput.val(4);
$newinput.attr("name","item1_id")
$("#form1").append($newinput,"Item 1<br>");
});

How do I deactivate Bootstrap-wysihtml5 jquery editor instance?

I'm using the Bootstrap-wysihtml5 jquery plugin (https://github.com/jhollingworth/bootstrap-wysihtml5/) to convert textareas to WYSIWYG. I would like to be able to activate and deactivate the editor by clicking on 2 buttons, so far i can show the editor, please will you let me know how i can deactivate the editor and leave just the textarea and its value. My code is as follows:-
HTML
<textarea name="textarea" id="textarea" cols="45" rows="5"></textarea>
<input type="button" id="button1" value="Show Editor">
<input type="button" id="button2" value="Hide Editor">
Script
$("#button1").click(function(){
$('textarea').wysihtml5();
});
$("#button2").click(function(){
// this is where i'm stuck
});
Thank you
A few lines of custom JS code. I think they can help you.
var content = $('#content');
var contentPar = content.parent()
contentPar.find('.wysihtml5-toolbar').remove()
contentPar.find('iframe').remove()
contentPar.find('input[name*="wysihtml5"]').remove()
content.show()
I had the same problem trying to disable/hide the toolbar and editor and had luck with the following commands (to disable the editor). I'm using version wysihtml5-0.3.0_rc2.js)
$('#editorId').data('wysihtml5').editor.composer.disable();
$('#editorId').data('wysihtml5').editor.composer.enable();
or (to hide the editor)
$('#editorId').data('wysihtml5').editor.composer.hide();
$('#editorId').data('wysihtml5').editor.composer.show();
To do the same to the toolbar you do the following to hide/show (can't find a wat to disable the toolbar):
$('#editorId').data('wysihtml5').editor.toolbar.hide();
$('#editorId').data('wysihtml5').editor.toolbar.show();

Avoid modal dismiss on enter keypress

I have set up a bootstrap modal with a form inside it, I just noticed that when I press the Enter key, the modal gets dismissed.
Is there a way not to dismiss it when pressing Enter?
I tried activating the modal with keyboard:false, but that only prevents dismissal with the ESC key.
I just had this problem too.
My problem was that i had a close button in my modal
<button class="close" data-dismiss="modal">×</button>
Pressing enter in the input field caused this button to be fired. I changed it to an anchor instead and it works as expected now (enter submits the form and does not close the modal).
<a class="close" data-dismiss="modal">×</a>
Without seeing your source, I can't confirm that your cause is the same though.
Just add the type="button" attribute to the button element, some browsers interpret the type as submit by default.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Attributes
This applies for all the buttons you have in the modal.
<button type="button" class="close" data-dismiss="modal">×</button>
I had this problem even after removing ALL buttons from my Bootstrap Modal, so none of the solutions here helped me.
I found that a form with a single text field would cause the browser to do a form submit (and result in dismiss), if you hit Enter while keyboard focus is on the text field. This seems to be more of a browser/form issue than anything with Bootstrap.
My solution was to set the form's onsubmit attribute to onsubmit="return false"
This may be a problem if you are actually using the submit event, but I'm using JS frameworks that generate AJAX requests rather than doing a browser submit, so I prefer disabling submit entirely. (It also means I don't have to manually tweak every form element that might trigger a submit).
More info here: Bootstrap modal dialogs with a single text input field always dismiss on Enter key
I had same problem, and i solved it with
<form onsubmit="return false;">
but there is one more solution, you can add dummy invisible input, so your form would look like this:
<form role="form" method="post" action="submitform.php">
<input type="text" id="name" name="name" >
<input type="text" style="display: none;">
</form>
You can put the login button before the cancel button and this would solve the issue you are having as well.
<div class="modal-footer">
<button type="submit" class="btn primary">Login</button>
<button type="submit" class="btn" data-dismiss="modal">Cancel</button>
</div>
I had a similar experience just now and the way I solved it was instead of using a tag, I changed the tag to an tag with type="button". This seemed to solve the problem of pressing the "enter" key and dismissing the bootstrap modal.
I had this problem too and I solved it this way. I added onsubmit to form. I also wanted to be able to use enter key as a saving key so I added save_stuff() javascript to onsubmit. return false; is used to prevent the form submit.
<form onsubmit="save_stuff(); return false;">
...
</form>
<script>
function save_stuff(){
//Saving stuff
}
</script>

Show 'Search' button in iPhone/iPad Safari keyboard

I've noticed navigating in websites like Dell or Google, that typing in their search text box with iPhone, in the keyboard appears a blue button 'Search' instead of the standard 'Go' button that appears on any normal form.
What should you do to display the search button?
having type="search" is usually all you need to make software Search keyboard appear however in iOS8 it is mandatory to have a wrapping form with action attribute.
So the following code would have a software keyboard with “Return” button
<form>
<input type="search" />
</form>
But this code should have blue “Search” button instead
<form action=".">
<input type="search" />
</form>
You can influence this behaviour with:
<input type="search" />
JS Bin demo
Ignore the submit button's text being 'kettle,' I just wanted to be sure that it wasn't the submit button influencing the text of the iOS keyboard...
This is, of course, backwards compatible since a browser that doesn't understand type="search" will default to type="text", which is useful for creating forward-planning html5 forms.
I was not able to get the search button with
<input type="search" />
However, I did get it to appear with
<form>
<input name="search" />
</form>
On iOS 8 you can enable the blue "Search"-button on the keyboard by doing one of:
add input name=search
add input type=search
add id to input with the case sensitive word "search" in the ID, for
example the-search or thesearchgod
In HTML5 standard, adding enterkeyhint attribute on the input is the proper way to change the label on the virtual keyboard
<input enterkeyhint="search" />
If no enterkeyhint attribute is provided, the user agent might use contextual information from the inputmode, type, or pattern attributes to display a suitable enter key label (or icon).
See MDN Docs about enterkeyhint
When using #Anton Bielousov suggested solution, this also changes the styling of Android Devices. To counter this I had to:
Add form around input.
Add type="search"
Add name containing search
Add styling to counter the unwanted android styling
Android styling:
input[type=search] { -webkit-appearance: none; }
/* clears the ‘X’ from Internet Explorer */
input[type=search]::-ms-clear { display: none; width : 0; height: 0; }
input[type=search]::-ms-reveal { display: none; width : 0; height: 0; }
/* clears the ‘X’ from Chrome */
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-results-button,
input[type="search"]::-webkit-search-results-decoration { display: none; }
<form action="" class="search-bar__form-form">
<input
class="search-bar__input"
name="search-bar"
type="search"
/>
</form>
The keyboard is handled by the operating system (iOS) and cannot be directly altered. The type of input required determines the type of keyboard to display.
If the website in question is HTML5, then #David's answer is valid.

In IE8 enter key in a form does not work

I have a problem that in IE8 the enter does not work to submit a form. I have generated a test page to expose this problem. It seems that displaying the form in the onLoad function disables results that the enter button does not trigger a submit anymore. Is this a bug in IE8 or is it some security issue?
The code to reproduce this is:
onload = function() {
document.getElementById('test').style.display = 'block';
}
#test {
display: none;
}
<form id="test" method="get" action="javascript:alert('woei!')">
<input type="text" name="user" value="">
<input type="password" name="pw" value="">
<input type="submit" value="submit" id="submit">
</form>
I have found a proper solution and wanted it to share with u guys.
Instead of using <input type="submit...>, use <button type="submit"...>.
This will do exactly the same in the other browsers (IE6-7, FF3) AND works in IE8. :)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
#test {
display: none;
}
</style>
<script type="text/javascript">
onload = function() {
document.getElementById('test').style.display = 'block';
};
</script>
</head>
<body>
<form id="test" method="get" action="javascript:alert('woei!')">
<input type="text" name="user" value="" />
<input type="password" name="pw" value="" />
<button type="submit" value="submit" id="submit"></button>
</form>
</body>
</html>
$("form input").keypress(function (e) {
if(e.which === 13) {
$("form").submit();
}
});
Above is a proper fix. Ref: IE Not submitting my form on enter press of enter key?
I think everthing is much more complicated than you think...
when a form's display value is set to none with a css class or just with a style attribute on page inital, hitting the enter key in a text field does not work only if you have more than one input field with text type... if you have one text field it works fine.. if you have more than one, it does not fire form submission...
Here i made a demo...
Works Fine (Normal Form)
http://yasinergul.com/stackoverflow/ie8-enter-key-bug/one.html
Works Fine (Form hidden & set back visible but it's with one text input)
http://yasinergul.com/stackoverflow/ie8-enter-key-bug/two.html
Does Not Work (Form hidden & set back visible but it's with two text input)
http://yasinergul.com/stackoverflow/ie8-enter-key-bug/three.html
i think the best approach is to give a .hidden class to the object but not setting display:none for this css selector. you can make it hidden with jquery like
$(".hidden").hide();
as the page loads the form is shown for miliseconds but gets hidden after jquery works...
I can't say if it is a bug exactly, but I can confirm that the behavior you report has changed in IE 8... and I imagine it is probably a bug, not an deliberate change.
If the form is set with CSS display:none the default submit button behavior doesn't work.
Other browsers, including IE 7 (or even IE 8 using IE 7 standard compatibility mode) do not have problems.
I've worked around the problem myself by just using height:0px; in the CSS, then having javascript set the appropriate height when I want to show the form. Using height instead, the default enter key submit behavior seems to work normally.
Old ticket, but I'd like to add what I think is the explanation:
IE8 does the following peculiar thing: the Enter key will submit the form, but any
<input type="submit" name="MySubmitButton" value="I hope I detect THIS VALUE in POST" />
won't be sent in the POST.
IE9 changes the behavior and sends the value. Chrome has always sent the value, as far as my tests have shown.
I hope this helps...
For any future users stumbling upon this question:
What worked for me was adding a DOCTYPE:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
A fix to what #Jitendra Pancholi suggested- now it submits only the form we want, not all of them
$("form input").keypress(function (e) {
if(e.which === 13) {
$(this.form).submit();
}
});
I tried it in IE8 and it works for me. You have to make sure that part of the form has focus though.
Javascript has a focus function that you can use to set the focus if that's what you need.
var textbox = document.getElementById("whatever name input box's id will be");
if(textbox) textbox.focus();
You may want to add a onkeyup event to your input boxes so that if you hit an enter in the input box then it will also submit.
As CodePartizan mentioned, you need the focus on the button otherwise, so if you tab over to the button, or click on it, it seems to work for me also.
I believe Yasin has got the point.
I just had the same problem: multiple text fields within a form whose visibility is "hidden".
My workaround (to prevent the form from flashing) is to set the form opacity to 0 in the css, and then customise its style settings with jQuery on document ready.
I believe this is not something to fix with JS.
Yeah, I was bitten by this bug too today. I found this workaround, though (diff from the OP):
<script type="text/javascript">
onload = function() {
document.getElementById('test').style.display = 'block';
+ document.getElementById('test').innerHTML =
+ document.getElementById('test').innerHTML;
}
</script>
</head>
Simply recreate the contents of the form from the contents of itself. Yikes. But it works. (Famous last words...)
This works for me in IE8. I had this problem when using only one input field.
Read more: http://www.rachaelarnold.com/dev/archive/enter-key-form-submission-bug#ixzz2Y5Zwgj2k
I had the same issue with ie and none of the solutions helped until I read this:
http://www.rachaelarnold.com/dev/archive/enter-key-form-submission-bug#ixzz2Y5Zwgj2k
my form only had one input field....duh! :)
Found a working solution.
Make the submit button invisible instead of using display:none;
input#submit {
color: transparent;
background: transparent;
border: 0px;
}