We have moved to a new Sailfish OS Forum. Please start new discussions there.
1

SDK : add a way to reset a ValueButton to a default value

asked 2014-10-10 17:00:15 +0300

I think it would be cool if you could add a defaultValue property to ValueButton, and a way to reset ValueButton.value to that defaultValue.

For example, let's say you have an app where a user CAN chose to set a deadline for something. He presses the ValueButton, which brings a DatePickerDialog up. The user choses a date and validates : everything's OK. But now, let's say the user changes in mind and he wants to remove this deadline. With a simple ValueButton, he just can't :(

I personnaly fixed this by adding a defaultValue property of type variant in my ValueButtons. For now, I'm also using the onPressAndHold event handler to reset value to defaultValue.

I think it could be cool to add this (or something similar that might fit better) in the official ValueButton component.

edit retag flag offensive close delete

1 Answer

Sort by » oldest newest most voted
1

answered 2014-10-13 16:47:27 +0300

So, I figured out that the Sailfish-way to do this might be to add a ContextMenu to the ValueButton. An item of this ContextMenu allows the user to clear (or reset) the value with a RemorseItem.

Here is some code, just in case :

ValueButton {
    id: vbutton

    property var defaultValue: ""

    ContextMenu {
        id: menu

        MenuItem {
            text: qsTr("Reset to default value")
            onClicked: {
                remorse.execute(vbutton, qsTr("Resetting to default value"), function() {
                    vbutton.value = vbutton.defaultValue
                })
            }
        }

        MenuItem {
            text: qsTr("Another action")
            onClicked : {
                // whatever
            }
        }
    }

    RemorseItem {
        id: remorse
    }

    onPressAndHold: {
        if(value !== defaultValue)
            menu.show(vbutton)
    }
}

Also note that this won't fit in a Column, but that's another story... :(

edit flag offensive delete publish link more
Login/Signup to Answer

Question tools

Follow
1 follower

Stats

Asked: 2014-10-10 17:00:15 +0300

Seen: 104 times

Last updated: Oct 13 '14