Slider in a form - not saving data

Not sure if this should be posted on form or slider topics but I’ll try slider first…

I have a form that shows records from a datastore.

I have a slider that is in a container control on the form.
myslider = new htmlXSlider(myform.getContainer(“mysliderContainer”));

The slider appears as expected in the form.

I then link the slider to an input control on the form.
myslider.linkTo(myform.getInput(“mysliderInputControl”));

The value in the input control changes as the slider is moved up and down as expected.

So far, so good.

Here’s the problem…
If the value shown in the input control is changed via the slider and the form is saved that value is NOT saved in the datastore. However if the value in the input control is changed by typing in a new value and the form is saved then it is saved in the datastore.

Any ideas why the value is not being saved when the change is made via the slider?

You need to set new value to form.
I.e. by “onSlideEnd” event

mySlider.attachEvent("onSlideEnd",function(newValue){ myForm.setItemValue("linkedInput", newValue) console.log(myForm.getFormData()) });

Thanks Darya. That worked.
Not sure I understand the purpose of the slider “linkedTo” if this has to be implemented. Might as well just use a slider onChange event so that the input control is forced to the slider value.

Also found out that the slider needs to be set via an onRowSelect event if the record shown in a form is changed where the form is bound to a grid.

I was expecting that “linkedTo” would take away the need to code those events. But no matter…

A quick question…
Is there a way to determine a slider’s parent container or attach user data to the slider object? Without going in to too much detail I’m trying to automate adding of sliders to forms based on the name pattern used for the container controls on the forms. I’m using “foreachitem” and if the item is a container and the container’s name matches the pattern “xxx_slider_SomeInput” then I create another slider in an array of slider objects. So when a slider event get triggered I’m having trouble working out which slider in the array is the one I need to deal with. Is the any function like myslider.getParentContainerId() or myslider.setUserData()?

Slider’s method linkTo will paste value in input, but it will be just slider-input on client relations, not slider-form on server. In the result getItemValue will get incorrect result, because form will not know that value changes (formdata is saved inside the whole component, not in each item, i.e. input)

About your question: could you clarify it, please? May be you can provide more details, code snippets, describe current and expected behaviour?

Hi Darya,
Thanks - that explains what’s happening.

I found a way around my issue using the slider object base.name property.

In my case I have a number of forms in tabs (or views) in a layout cell and each form may have one or more sliders. I have many tables to deal with in this way so I am creating a template html that allows setting a few javascript variables to determine which table and forms need to be provided on page call-up. And rather than hard code an object for each form and for each slider I use arrays - form[] and slider[]. As each form or slider is initiated I increment an appropriate index for the array.

Now I can attach an event to slider[x] of form[y] when the slider is initiated. But when the event is triggered I didn’t know which form in the form array the slider belonged to. But I found the base.name property and used it as per the code below.

There may be a better way however it works this works ok.

function doonload() {
… // All the other things happening onload

slider[x].attachEvent(“onSlideEnd”, function(value) {
var tmp_id = this.base.name;
// this is the slider object and this.base.name gives the name of the container on the form that holds this slider. Syntax for container id is “cntr_slider_”
var tmp_form = fnc_find_form(tmp_id); // call the function to find the slider’s form
if (tmp_form) {
var tmp = tmp_id.split("_"); // The
tmp_form.setItemValue(tmp[3], value);
}
});

… // More stuff onload
}

function fnc_find_form(id) {
// Function to find which form contains an Item with the matching id
for (var i = 0; i< form.length; i++) {
if (form[i].isItem(id)) {
return form[i]; // Ok, found the form so return the form object
}
}
return false; // Didn’t find he form so return false.
}