Material Slider with min and/or max value, wrong behaviour for Input Filed

+1 vote
asked Apr 5, 2016 in Issue by Cheras
Hi,

If I have slider with constrains set, let's say minimum value is 50 and then try edit value in Input field, there is problem of Input being overridden by min value when all Input value is initially selected.

To see it in editor:

1. Create slider with limit (i.e 50) and set it to some value (ie. 60)

2. Select input field.

- notice all of input text is fully selected

3. Try type 70, field will be updated to 50

My guess is, because all of text is preselected, 60 is being replaced with one character, that is 7, then there's chain of events input changed -> slider update -> slider changed - > validate slider -> update input with validated value (50)

It's more noticeable on Android, where it's quite confusing to users.

 

Question:

How can we fix it? We cannot really wait for next release of plugin as we're finishing polishing UI and want to subtmi asap

Plugin version 1.0.0, cannot update

Thank you!
commented Apr 5, 2016 by admin (31,720 points)
I can reproduce this, give me a moment to work out a fix :)

~ Declan.

1 Answer

0 votes
answered Apr 5, 2016 by admin (31,720 points)
 
Best answer

Okay, try this:

In MaterialSlider.cs, on line ~721, there should be this:

slider.value = floatValue;

Change it to this:

if (floatValue >= slider.minValue && floatValue <= slider.maxValue)
{
    slider.value = floatValue;
}

Let me know if that does what you wanted :)

~ Declan.

PS: To anyone else reading, this will be fixed in v1.1.3

commented Apr 5, 2016 by Cheras
Works :) Thank you!
commented Apr 5, 2016 by Cheras
One idea though, not sure what's better. If the input edit change, maybe it's better to update the value with min/max if input value is outside range?

Now, let's say I have slider with 50,100 range, then I type 70 - it sets slider  to 70. I continue typing and Input is 700. When I click outside, input changes to 70. maybe it should be 100?
commented Apr 5, 2016 by admin (31,720 points)

Try replacing both that method and the one below it, with this block of code:

private float m_CurrentInputValue = 0f;

public void OnInputChange(string value)
{
    float floatValue;
    if (float.TryParse(value, out floatValue))
    {
        m_CurrentInputValue = floatValue;
        if (floatValue >= slider.minValue && floatValue <= slider.maxValue)
        {
            slider.value = floatValue;
        }
    }
}

public void OnInputEnd()
{
    if (m_InputField != null)
    {
        slider.value = m_CurrentInputValue;
        m_InputField.text = slider.value.ToString();
    }
}

That should do what you're looking for :)

~ Declan.

Welcome to MaterialUI support! Ask us anything :)
...