Foundation 6 Range slider - update input value when user lets go of the handle - slider

I browsed throught the docs of Foundation 6 and couldn't find a solution to my problem.
I have an input filed bound to the range slider and would like to call a function that formats the input value once the user lets go of the handle (I have to to this since the slider can't handle values with commas and dots, like 1,200.87).
I thought the moved.zf.slider event would be ideal for that, the documentation says that it fires when the handle is done moving, however it fires multiple times as long as the handle is being moved and I would like it to fire just once, when user lets go of the mouse button/stops touching the screen.
Can this be done?

moved.zf.slider fires each time the handle is finished moving (e.g. between snapped increments) so you want a function that is based on the pause after interaction with a range input, that's changed.zf.slider in combination with data-changed-delay
So your HTML would be something like:
<div class="slider vertical" data-slider data-initial-start="25" data-end="200" data-vertical="true" data-changed-delay="2000">
<span class="slider-handle" data-slider-handle role="slider" tabindex="1"></span>
<span class="slider-fill" data-slider-fill></span>
<input id="result" type="hidden">
</div>
Where data-changed-delay="2000" is the time in miliseconds you want to wait for before deciding they're done (2 seconds is probably quite long, but it makes it easier to see it working). You could also do this via jQuery too of course. N.B. The default if you don't set it explicitly is 500ms which is a pretty good guess of the pause time.
Then your jQuery is something like this:
$('.slider').on('changed.zf.slider', function() {
//do whatever when user is done with the range slider
});
All this does is wait for the trigger (changed.zf.slider) and then run the script enclosed.
I've put an example on JSFiddle
Reference in Foundation docs

Related

Testcafe - Selecting checkbox using id always end up with the full timeout wait

Our html codes for checkbox always look something like this
<div id="paymentCheckBoxesMod" class="c-form__checkbox-container u-spacing__margin-bottom--16 u-spacing__margin-top--16">
<input type="checkbox" id="supplementaryAgreement" aria-describedby="paymentsCheckboxLabel">
<label for="supplementaryAgreement">
</label>
<div id="paymentsCheckboxLabel">
Jag godkänner Storytels <span id="purchasetermspopup">Köpvillkor</span> & <span id="privacypolicypopup">Integritetspolicy</span>
</div>
</div>
ive always located the element using the label's for="supplementaryAgreement" because if i use the input's id="supplementaryAgreement"i end up having to wait for the timeout duration before the element is located. Does anyone know why?
so that has worked fine until i have to work for iframes and although ive already switched back to mainframe however i will get the error that there is no match on the DOM tree if i use for="supplementaryAgreement" now. It still work with id="supplementaryAgreement" but having to wait for it to timeout doesn't seem efficient.
I think that the cause of this issue is in the complex markup of your checkbox. It seems that the checkbox is overlapped by the label::after element, so TestCafe cannot correctly find the checkbox. The other issue is that label[for=supplementaryAgreement] has height equal to 0.
Your idea with decreasing the timeout for the selector is a good workaround in this case. It does not work since there is a syntax mistake. Please try the following approach: Selector('#supplementaryAgreement', { timeout: 1000 })

How to set the default value of input item with jQuery EasyUI framework

I am trying to set the default value of an input item from last two days.
For this, i have also searched in google but till not cannot find the solution.
I am using jQuery EasyUI framework.
<div class="fitem">
<tr>
<td></td>
<td>
<input type="text" class="easyui-validatebox" name="insertby" id="insertby" size="20">
</td>
</tr>
</div>
<script>
var s = '<?php echo $logname; ?>';
document.getElementById('insertby').value = s ;
alert(s);
</script>
As I am unable to add a comment to ask you to try stuff, I will try my best to help you out!
Firstly, your code works for me. However, there are times where other javascript codes causes errors and stops the code execution before your block of code. You might want to try pressing F12 on your Chrome browser to see if you encounter any errors before your block of code to ensure that all is well.
this code snip might have you
http://www.jeasyui.com/forum/index.php?topic=2623.0
$('#insertby').validatebox('setValue', s);
I took me while to "get it" too.
Actually, jquery easyUI modifies the DOM on the fly to make its fancy things in a way that the original input box is "gone" while you obtain their fancy widget instead. That's why modifying the input field directly has no effect, it is hidden actually. I guess this is done so because their getters/setters should be used in order to update everything correctly.
EasyUI is very easy to set up and play with, but it's way to operate on elements is rather unintuitive. But once you got the hang of it, it should be all right.
Use
setValue. $('idofcombogrid').('setValue',id_value);
The id_value refers to the value of idField as defined initially for the combogrid.

dijit.form.Select won't set value programmatically

I have a dynamic dojo form in which I have a dijit.form.Select whose selected value I have tried to set dynamically through various ways. I get the select widget to load and show the data, but it always ignores my every attempt. I am using dojo 1.7.
var bcntryval = <?= $this->billingContact->countryId;?>;
var countryStore;
function onBillingShow() {
if (countryStore) countryStore.close();
countryStore = new dojo.data.ItemFileReadStore({url: 'CartUtilities.php?action=getcountries'});
dijit.byId("bcntry").setStore(countryStore, bcntryval); // does not set value! but does set the store
dijit.byId("bcntry").attr('value', String(bcntryval)); // doesn't set the value either
dijit.byId("bcntry").set('value', bcntryval)); // nor does this!
}
My markup for the bcntry widget is as follows:
<td><input data-dojo-type="dijit.form.Select" style="width: 10em;" data-dojo-props="sortByLabel:false, maxHeight:'-1'" data-dojo-id="bcntry" id="bcntry" name="bcntry" />
I've invested a fair amount of time on learning dojo. When it works its nice, but the docs leave a lot to be desired!
I am also seeing a similar problem with the dijit.form.FilteringSelect. That also ignores setting the value via javaScript.
I've also tried completely programmatic versions of this code. I have come to the conclusion that setting the value just doesn't work when you're selecting from a store.
This DID work, but its not dynamic.
<div name="scntry" data-dojo-type="dijit.form.Select" data-dojo-props="maxHeight:'-1',sortByLabel:false" value="<?= $this->shippingContact->countryId;?>" >
<?php foreach($this->countryList as $c):?>
<span value="<?= $c->id;?>"><?= $c->name;?></span>
<?php endforeach;?>
</div>
The reason most likely is, that youre trying to set the value of the 'searchAttr'. Instead you would want to set value to the 'identifier'.
Answer is here, check the timeout function on bottom shelf: http://jsfiddle.net/TTkQV/4/
The trick is to set the value as you would set option.value (not option.innerHTML).
normalSelect.set("value", "CA");
filteringSelect.set("value", "AK");
Take a look here, I believe this does what you want in the Dojo way:
Setting the value (selected option) of a dijit.form.Select widget
If not, you can always just use the actual dom selection object and use straight Javascript:
How do I programatically set the value of a select box element using javascript?

valueUpdate: 'afterkeydown' for input type="numeric" in Knockoutjs 2.0

[see fiddle for illustration]
I set up a value bind to an input of type number, and want the bound observable to immediately reflect changes to the value of the field. to do that I set the afterkeydown valueUpdate binding. This works well for changing the number input using the arrow up and arrow down keys. However, if I change the number using the browser-generated (tested in chrome) increment/decrement control the change is only reflected upon changing focus to a different element. I assume this reflects the default update upon change event.
My question is whether there is any way to set the update to occur for both changes using the up down keyboard errors and browser-generated up/down error controls?
The valueUpdate additional binding can take an array of events. It looks like the oninput event is fired when clicking on the up/down arrows.
So, you can bind it like:
<input type="number" data-bind="value: y, valueUpdate: ['afterkeydown', 'input']"/>
http://jsfiddle.net/rniemeyer/hY5T2/9/

Refining my Dojo/Dijit NumberTextBox numeric validation

I have the following code:
<input type="text" dojoType="dijit.form.NumberTextBox" size=8
constraints="{min:0,max:100000,places:0}"
id="orgNumberOfStudents" name="orgNumberOfStudents"
required="true" invalidMessage="Integer between 0 and 100,000"
value="">
Questions:
1) How do I set the width of the box? Do I have to do it in a style tag or a CSS? Is the traditional "input size" tag ignored?
2) The above sample shows the error when I type in a non-numeric value. But if I tab over the field and don't fill in anything, it's still blank. Is there a quick way to enforce the validation when I click the submit button? Do I need a Dijit submitt button? Do I need to write more JavaScript to make this happen? How does the required="true" actually occur?
(One get-around is to set the value to 0, but I'd rather force the user enter a value rather than just defaulting it).
Thanks,
Neal Walters
You should be able to use both CSS and traditional INPUT attributes like "maxLength" on your NumberTextBox by passing them in to the Widget's constructor. maxLength is available on all dijit.form.TextBox subclasses, but is probably less useful here since you have control over things like min/max and the actual number format.
Yes, you can always write your own JS to test "isValid()" on your widget instance before submission, e.g. in an HTML FORM onSubmit handler, or you could use dijit.form.Form which will check validity for you. The widget itself is only responsible for visual representation of its own validity, according to the options chosen.
HTH