jQuery Mobile focus next input on keypress - input

I have a jquery mobile site with a html form consisting of 4 pin entry input boxes. I want the user to be able to enter a pin in each input field without having to press the iphone keyboards "next" button. I have tried the following and although it appears to set the focus to the second input and insert the value, the keyboard disappears so the user still has to activate the required input with a tap event.
$('#txtPin1').keypress(function() {
$('#txtPin1').bind('change', function(){
$("#txtPin1").val($("#txtPin1").val());
});
$("#txtPin2").focus();
$("#txtPin2").val('pin2');
});
Is there a different event that I should be assigning to $("#txtPin2")?
I have tried to implement http://jqueryminute.com/set-focus-to-the-next-input-field-with-jquery/ this also, but I found that it worked for android and not for iphone.
Any help is greatly appreciate it.

Live Example: http://jsfiddle.net/Q3Ap8/22/
JS:
$('.txtPin').keypress(function() {
var value = $(this).val();
// Let's say it's a four digit pin number
// Value starts at zero
if(value.length >= 3) {
var inputs = $(this).closest('form').find(':input');
inputs.eq( inputs.index(this)+ 1 ).focus();
}
});
HTML:
<div data-role="page" data-theme="b" id="jqm-home">
<div data-role="content">
<form id="autoTab">
<label for="name">Text Pin #1:</label>
<input type="text" name="txtPin1" id="txtPin1" value="" class="txtPin" placeholder="Please enter Pin #1"/>
<br />
<label for="name">Text Pin #2:</label>
<input type="text" name="txtPin2" id="txtPin2" value="" class="txtPin" placeholder="Please enter Pin #2"/>
<br />
<label for="name">Text Pin #3:</label>
<input type="text" name="txtPin3" id="txtPin3" value="" class="txtPin" placeholder="Please enter Pin #3"/>
<br />
<label for="name">Text Pin #4:</label>
<input type="text" name="txtPin4" id="txtPin4" value="" class="txtPin" placeholder="Please enter Pin #4" maxlength="4"/>
</form>
</div>
</div>

I tried it on android and it works. I can not check it on iPhone.
Check this: http://jsfiddle.net/Q3Ap8/276/ [direct link: http://fiddle.jshell.net/Q3Ap8/276/show/ ]
$('.txtPin').keydown(function() {
that=this;
setTimeout(function(){
var value = $(that).val();
if(value.length > 3) {
$(that).next().next().next().focus().tap();
}
},0);
});
Other solution that works for android is:
http://jsfiddle.net/Q3Ap8/277/ [ http://jsfiddle.net/Q3Ap8/277/show ]
$('.txtPin').keydown(function() {
that=this;
setTimeout(function(){
var value = $(that).val();
if(value.length > 3) {
$(that).next().next().next().click();
}
},0);
});
$('.txtPin').click(function() {
$(this).focus().tap();
});

Related

Vue click two input one button

I want to pick a new value when the button is clicked, but I can't
<div class="col-lg-12 col-sm-6 col-4" style="margin-top:5px;">
<p style="margin-bottom:0rem;" > Цена</p>
<label>
<input id="PriceRangeMin" type="number" :value='text' >
-
<input id="PriceRangeMax" placeholder="до" type="number" :value='text1'>
</label>
<button id="PriceRangeMin" type="submit" style="margin-left:30px;" #click='textcon()'>Применить</button>
</div>
My script
<script>
export default {
name: 'Applesmartphone',
data () {
return {
text:[],
text1:[]
}
},
methods: {
textcon(){
console.log(text)
console.log(text1)
}
}
}
Hi, I want to pick a new value when the button is clicked, but I can't.
Bind input to properties using v-model like :
input id="PriceRangeMin" type="number" v-model='text' >
then use this to access that properties inside the method :
textcon(){
console.log(this.text)
console.log(this.text1)
}

Vue Validator only after change / blur / submit

I'm using Vue for the first time, with Vue Validator. Here is an example of my code:
<label for="first_name">First name:
<span v-if="$validation1.first_name.required" class="invalid">Enter your first name.</span>
<input id="first_name" placeholder="e.g. Christopher" class="" v-validate:first_name="['required']" v-model="first_name" name="first_name" type="text">
</label>
The only issue at the moment is that when I land on the page with my form, the whole thing is covered in errors. Is there a way I can suppress the errors and only show them on input blur / form submit?
Argh, the Google-able word isn't about blur, or on submit – its about timing and initial:
http://vuejs.github.io/vue-validator/en/timing.html
<input id="first_name" initial="off" placeholder="e.g. Christopher" class="" v-validate:first_name="['required']" v-model="first_name" name="first_name" type="text">
you need to add .dirty or .touched to your validation
<label for="first_name">First name:
<span v-if="$validation1.first_name.required && $validation1.first_name.touched" class="invalid">Enter your first name.</span>
<input id="first_name" placeholder="e.g. Christopher" class="" v-validate:first_name="['required']" v-model="first_name" name="first_name" type="text">
</label>
I was dealing with a similar problem. I had to have an initialized variable for the input name: "" but I also wanted to have a required attribute in element.
So I add required when the event onblur occurs.
<input name="name" type="number" v-model="name" #blur="addRequired" />
const app = Vue.createApp({
data() {
return {
name: ""
}
},
methods:{
addRequired: function(event){
event.target.setAttribute("required", true);
}
}
});

How to turn off the webcam after using Pubnub?

I started to use Pubnub for making video group chats. However, when I was testing it, I found a little problem: As I connect my computer to their servers, my webcam turns on and never turns off, unless I leave the page.
However, I wish to be able to close a video chatting, and turning off the webcam at the same time. How to do it?
Thank you very much!
EDIT: Here is a code I'm using for my tests, I'm using the one given in the tutorial:
<script src="js/jquery-2.1.4.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="js/pubnub-3.7.18.min.js"></script>
<script src="js/webrtc.js"></script>
<script src="js/rtc-controller.js"></script>
<div id="vid-box"></div>
<div id="vid-thumb"></div>
<form name="loginForm" id="login" action="#" onsubmit="return login(this);">
<input type="text" name="username" id="username" placeholder="Pick a username!" />
<input type="submit" name="login_submit" value="Log In">
</form>
<form name="callForm" id="call" action="#" onsubmit="return makeCall(this);">
<input type="text" name="number" placeholder="Enter user to dial!" />
<input type="submit" value="Call"/>
</form>
<div id="inCall"> <!-- Buttons for in call features -->
<button id="end" onclick="end()">End</button> <button id="mute" onclick="mute()">Mute</button> <button id="pause" onclick="pause()">Pause</button>
</div>
<script>
var video_out = document.getElementById("vid-box");
var vid_thumb = document.getElementById("vid-thumb");
function login(form) {
var phone = window.phone = PHONE({
number : form.username.value || "Anonymous", // listen on username line else Anonymous
media : { audio : true, video : true },
publish_key : 'pub-c-c66a9681-5497-424d-b613-e44bbbea45a0',
subscribe_key : 'sub-c-35aca7e0-a55e-11e5-802b-02ee2ddab7fe',
});
var ctrl = window.ctrl = CONTROLLER(phone);
ctrl.ready(function(){
form.username.style.background="#55ff5b"; // Turn input green
form.login_submit.hidden="true"; // Hide login button
ctrl.addLocalStream(vid_thumb); // Place local stream in div
}); // Called when ready to receive call
ctrl.receive(function(session){
session.connected(function(session){ video_out.appendChild(session.video); });
session.ended(function(session) { ctrl.getVideoElement(session.number).remove(); });
});
ctrl.videoToggled(function(session, isEnabled){
ctrl.getVideoElement(session.number).toggle(isEnabled); // Hide video is stream paused
});
ctrl.audioToggled(function(session, isEnabled){
ctrl.getVideoElement(session.number).css("opacity",isEnabled ? 1 : 0.75); // 0.75 opacity is audio muted
});
return false; //prevents form from submitting
}
function makeCall(form){
if (!window.ctrl) alert("Login First!");
else ctrl.dial(form.number.value);
return false;
}
function end(){
ctrl.hangup();
}
function mute(){
var audio = ctrl.toggleAudio();
if (!audio) $("#mute").html("Unmute");
else $("#mute").html("Mute");
}
function pause(){
var video = ctrl.toggleVideo();
if (!video) $('#pause').html('Unpause');
else $('#pause').html('Pause');
}
</script>
Note that I tried to find the function through the console in addition to my searches, but I was unable to find it...

BootstrapValidator: How to use use two submit buttons and validate different fields on same form?

So i have a form that has two submit buttons, but for each i want to validate different fields, in this case when i click on the preview submit button i want to ignore 3 fields, while in the 'normal' submit button i want to validate all. Is this possible?
Here's some html:
<form class="form" role="form" id="searchesForm">
<input class="form-control" type="text" id="name" name="name"/>
<input class="form-control" type="text" id="widgetWidth" name="widgetWidth" />
<input class="form-control" type="text" id="widgetHeight" name="widgetHeight" />
<!-- More fields validated for both button clicks-->
...
<button type="button" id="preview" name="previewSearch" class="btn btn-default" >
Preview
</button>
<button type="submit" id="submit" name="submitSave" class="btn btn-primary">
Save
</button>
</form>
So the idea is that when i press the preview button these 3 fields(name, widgetWidth and widgetHeight)
should be ignored, but not when i press the save button.
Here's my bootstrap validator:
$('#searchesForm').bootstrapValidator({
excluded: ['td>select,td>input,td>textarea'],
feedbackIcons:{
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
live:'submitted',
submitButtons:'[type="submit"]',
fields: {
name: {
validators: {
notEmpty: {
enabled:function(){
debugger;
alert("testes");
},
message: 'The question required and cannot be empty'
}
}
}
}
}).on('success.form.bv',function(e){
// Prevent form submission
e.preventDefault();
//check which button was pressed
var button=$(e.target).data('bootstrapValidator').getSubmitButton();
if($(button).attr("id")==="preview"){
previewSearch();//do ajax stuff
}else{
saveSearch();//do ajax stuff
}
}).on('error.form.bv',function(e){
var invalidFields=$(e.target).data('bootstrapValidator').getInvalidFields();
//show tab for specific fields location
$.each(invalidFields,function(index,value){
if($("#filtros").has(value).length > 0){
$('#tabs li:eq(0) a').tab('show')
}
if($("#resultado").has(value).length > 0){
$('#tabs li:eq(1) a').tab('show')
}
if($("#widget").has(value).length > 0){
$('#tabs li:eq(2) a').tab('show')
}
});
}).on('status.field.bv', function (e, data) {
if (data.bv.getSubmitButton()) {
data.bv.disableSubmitButtons(false);
}
if(data.bv.getSubmitButton()) {
if (data.bv.getSubmitButton().attr("id") === "preview"){
if (data.field === "name" || data.field === "widgetWidth" || data.field === "widgetHeight") {
data.bv.$form.bootstrapValidator('enableFieldValidators', data.field, 'notEmpty', false);
}
}else{
data.bv.$form.bootstrapValidator('enableFieldValidators', data.field, 'notEmpty', true);
}
}
});
I don't really know where can we enable/disable the field validator according to the button pressed. i tried to change the status of the fields validator on the .on('status.field.bv'...) method but it doesn't work completely.
Also the submitButtons don't seem to work if i choose something other than "type=submit".
So has anyone come up with this situation?

Unable to Disbale the DOJO dijit.form.Form

I have a Form and i want to disable the entire form on click of a Button ,please see this code
<div dojoType="dijit.form.Form" id="myForm" jsId="myForm" encType="multipart/form-data"
action="" method="">
<table>
<input type="text" id="name" name="name" required="true" dojoType="dijit.form.ValidationTextBox"
<input type="text" id="dob" name="dob" dojoType="dijit.form.DateTextBox"
</table>
<button dojoType="dijit.form.Button" type=button onClick="console.log(myForm.getValues())">
Get Values from form!
</button>
<button dojoType="dijit.form.Button" type="submit" name="submitButton"
value="Submit">
Submit
</button>
<button dojoType="dijit.form.Button" type="reset">
Reset
</button>
<button dojoType="dijit.form.Button" onClick="callMe()">
Disable IT
</button>
</div>
I have written a function callMe to disable this
function callMe()
{
dijit.byId('myForm').disabled=true;
}
Dijit forms do not have a property "disabled", but rather you have to overwrite the onSubmit event:
dijit.byId('myForm').onSubmit = function () {
// If we return false here, the form will not be submitted.
return myMagicEnabledFlag;
};
Note that you cannot use dojo.connect as you have to modify the return value of the event and not just connect to it.
For disabling the entire form elements, use the "getChildren()" function of the dijit form, which would return the array of all the field widgets of that corresponding form. Then, you need to disable the widgets of that array. See below sample:-
dijit.byId('myForm').onSubmit = function () {
var widgets = dijit.byId('myForm').getChildren();
for(var i=0;i<widgets.length;i++) {
widgets[i].set('disabled', true);
}
//if you need to prevent the form submission & just disable, return false,
//else ignore the following return stmt
return false;
};