What is the proper event for input="text" - ajax

I have an input field which is start_time and end_time and these fields are formatted with the data-format HH:mm:ss PP.
What I want to do is when the user is done entering the data, then I'll do some AJAX to calculate the time.
But, I'm a little bit confused because I don't know what is the proper event for the input fields. I tried keydown,keyup,focus but still doesn't work.
Here is the input field start_time:
<div class='input-append' id='datetimepicker2'>
<input data-format='HH:mm:ss PP' type='text' name="start_time" id="start_time" value="<?php echo set_value('start_time')?>"/>
<span class='add-on'>
<i data-date-icon='icon-calendar' data-time-icon='icon-time'>
</i>
</span>
</div>
</div>
<script type='text/javascript'>
$(function() {
$('#datetimepicker2').datetimepicker({
language: 'en',
pick12HourFormat: true,
pickDate: false
});
});
</script>
And for the end_time:
<div class='input-append' id='datetimepicker3'>
<input data-format='HH:mm:ss PP' type='text' name="end_time" id="end_time" value="<?php echo set_value('end_time') ?>"/>
<span class='add-on'>
<i data-date-icon='icon-calendar' data-time-icon='icon-time'>
</i>
</span>
</div>
</div><script type='text/javascript'>
$(function() {
$('#datetimepicker3').datetimepicker({
language: 'en',
pick12HourFormat: true,
pickDate: false
});
});
</script>

Go for onblur, sothat when the user finish entering the data in input field and gets focus out of the field the event gets triggered.
edited according to comments below
I guess you are using bootstrap datepicker in your code. If not so, please mention the datpicker or the js library that you are using.
In the case of bootstrap date picker yu can look at the changedate event for your task which will get triggered each time a change is made on your datepicker value. Also you can check the changeYear && changeMonth events also which are available.
here is a demo fiddle using the code you provided which will trigger an alert whenever a change is made on the corresponding datepicker. You can replace it with whatever code you want to execute on change.
sample code snippet
$('#datetimepicker2').datetimepicker({
language: 'en',
pick12HourFormat: true,
pickDate: false
}).on('changeDate', function (e) {
alert("first one changed"); // replace with your code block
});;

Related

Ember : if a value is set in controller , perform an Ajax command(written in template),

I have given a rough code to understand what I need to perform,
/app/route1/controller.js
export default Controller.extend({
test: function(id) {
$.ajax({
.....
.....
.....
}).then(() => {
set('message','successfully added');
});
}
});
/app/route1/template.hbs
<div class="ui container">
<div class="ui segment"
<button class="ui button" {{action "test" model.id}}>Submit</button>
</div>
</div>
<div class="ui container">
<div class="ui modal">
<div class="header"
Message
</div>
<div class="content"
{{message}}
</div>
<div class="actions">
<div class="ui ok button">OK</button>
</div>
</div>
</div>
<script type="text/javascript">
$.ajax({
if(message) {
$('.ui.modal').modal('show');
}
})
</script>
If I set a message in controller then, I have to show this message in the MODAL. The Ajax command that I've written is not correct., Please help to solve this issue.
Thanks in advance
First, you must not use <script> tags with ember. This won't work as expected and is in no way supported.
If you have to manually access DOM you should use the didInsertElement of a component.
Are you absolutly sure you want to build your modal yourself? There are many addons providing a nice API for modals. If you can use one of them. If you cant you basically have to write your own modal component.
I will not instruct your in detail how to do this, because this seems not to be your primary question.
Now about your test function. first you seem to try to use it as an action:
{{action "test" model.id}}
however for this you must place the function under the actions hash.
Next this line is wrong:
set('message','successfully added');
you either must use this.set('message','successfully added'); or set(this, 'message','successfully added');
Then you can display your message like this:
{{#if message}}
{{#modal-dialog
onClose=(action (mut isShowingBasic) false)
}}
{{message}}
{{/modal-dialog}}
{{/if}}
And it will work as expected.

putting validation on datepicker component of vuejs but its showing up the the error message by default

//this is my html code where i have a datepicker component wheer i want to throw a validation but i want the error message to be shown once the user leaves this feild and go on some other inputfeild of the form
<datepicker v-model="present_complaint.experienceSince"
name="date" placeholder=24-july-1994>
</datepicker>
<span class="error-msg" v-show="present_complaint.experienceSince ==''">
Date is a mandatory field
</span>
//this is my js code
present_complaint:{
description:'',
}
//currently when the page loads by default the error message is there on the datepicker as by default it is empty now i want that it should only be diaplayed when user clicks on it and leave it not selecting any date basically when it goes to any other feild and not selecting any date
I have a solution for you.
<div id="app">
<input type="text" placeholder="type something" v-model.trim="text" #blur="blur">
<span v-show="text === ''">Please Fill the input</span>
</div>
new Vue({
el: "#app",
data: {
text: null
},
methods: {
blur() {
if(this.text === null) {
this.text = ''
}
}
}
})
The answer it is simplified to understand the logic.Once you do,you can solve your problem by replacing some code.Take a look to the demo

How to give value to the bootstrap switch button?

I have a form in codeigniter where I've an option to show the data in the front page or not.
<div class="form-group input-group">
<label>Show in Front</label>
<input type="checkbox" id="switch-change" name="show-infront" checked data-on-text="YES" data-off-text="NO" checked data-on-color="success" data-off-color="warning">
</div>
<script type="text/javascript">
$("[name='show-infront']").bootstrapSwitch();
</script>
When I print the value of the form in controller like echo $this->input->post('show-infront'), when 'yes' is checked, the output is 'on' and when 'no' is checked, there is no any output. So, I want that when I check yes, then the value should be 'yes' and vice-versa.
try: onSwitchChange ...
OK so if checkbox in not checked not send its value in POST, so you need a hidden field like this:
also need set its value at init and onChange
<input type="checkbox" id="switch-change" name="show-infront" data-on-text="YES" data-off-text="NO" checked data-on-color="success" data-off-color="warning">
<input type="hidden" name="show-infront-val"/>
<script type="text/javascript">
var ckbox = $("[name='show-infront']");
var ckbox_val = $("[name='show-infront-val']");
ckbox.on('switchChange.bootstrapSwitch init.bootstrapSwitch', function(event, state) {
if (this.checked) ckbox_val.val('Yes')
else ckbox_val.val('No')
});
ckbox.bootstrapSwitch('state', true);
</script>
Btw if you check php-s isset($_POST['show-infront']) also a good option for one checkbox
Documentation

submit form at each step using Jquery form wizard

I am using Jquery Form wizard plugin in a MVC application. http://thecodemine.org/
I have a form with 4 steps. in one of step i have upload functionality.
I want submit functionality at each step and also back and next steps. later steps are optional.
I was able to add a submit button in navigation. On clicking it, form data related to active step is only submitted and other data is null.
For more clarity of my issue:
View :
<form id="myform" method="post" action="/Controller/Action">
<div id="fieldWrapper">
<fieldset class="step fieldset" id="first">
<legend class="legend">First step</legend>
Some input controls
</fieldset>
<fieldset class="step fieldset" id="second">
<legend class="legend">Second step</legend>
some more input controls (optional)
</fieldset>
<fieldset class="step fieldset" id="third">
<legend class="legend">Third step</legend>
some more input controls with filu upload
(optional)
</fieldset>
<fieldset class="step fieldset" id="fourth">
<legend class="legend">Fourth step</legend>
some more input controls (optional)
</fieldset>
</div>
<div id="demoNavigation">
<input class="navigation_button" id="back" value="Back" type="reset" />
<button type="submit" id="submitBtn">Submit and Finish</button>
<input class="navigation_button" id="next" value="Next" type="submit" />
</div>
</form>
Script:
<script type="text/javascript">
$(function () {
$("#myform").formwizard({
validationEnabled: true,
focusFirstInput: false,
disableUIStyles: true,
textSubmit: 'Submit and Finish',
textNext: 'Continue to next step',
next: "input:submit"
}
);
});
</script>
Updated the Jquery.form.wizard.js to so that the submit button hides at last step.
Now on each step i have submit button and navigation button.
When i submit form on second step, form data in second step is only posted and rest is not posted.
I went through the samples but could not find the appropriate one.
Can anyone suggest how to achieve this?
I went through the documentation and jquery.form.wizard.js file to get beeter understanding of what is done.
I just have to write some script as follows:
<script type="text/javascript">
$(function () {
$("#myform").formwizard({
validationEnabled: true,
focusFirstInput: false,
disableUIStyles: true,
textSubmit: 'Submit and Finish',
textNext: 'Continue to next step',
next: "input:submit"
}
);
});
$('#submitBtn').click(function () {
var stepInfo = $('#myform').formwizard('state');
for (var i = 0; i < stepInfo.activatedSteps.length; i++) {
stepInfo.steps.filter("#" + stepInfo.activatedSteps[i]).find(":input").not(".wizard-ignore").removeAttr("disabled");
}
});
</script>

Back to Top Link, Dynamically Created, with Scroll

SUMMARY:
I need to insert a "Back to Top" links after every <div class="wrapSection">. I've been successful using the following:
<script>
$('.wrapSection').after('
<div class="backToTop clearfix">
Back To Top
</div>
');
</script>
However, I want to use a smooth scroll when clicking 'Back to Top.' With that in mind, I tried the following:
<script>
$('.wrapSection').after('
<div class="backToTop clearfix">
<a href="javascript:void(0)" onclick="goToByScroll('top')" class="up">
Back To Top
</a>
</div>
');
</script>
That does not work. Being a jQuery rookie, I did what seemed logical, which seems to never be the correct answer.
IN A NUTSHELL
More or less, I need this to appear, dynamically, after every <div class="wrapSection">:
<div class="backToTop">
<a class="top" href="javascript:void(0)" onclick="goToByScroll('top')">
Back to Top
</a>
</div>
This is the solution I came up with:
​$(document).ready(function() {
// Markup to add each time - just give the element a class to attach an event to
var top_html = '<div class="backToTop">Back To Top</div>';
$(".wrapSection").after(top_html);
// Use event delegation (see http://api.jquery.com/on/)
$("body").on("click", ".top", function(e) {
e.preventDefault();
$("html,body").animate({ scrollTop: 0 }, "slow");
});
});​
You can try a jsFiddle here: http://jsfiddle.net/F9pDw/

Resources