MultiValue reset

MultiValue reset

RagnarGrootKoerkampRagnarGrootKoerkamp Posts: 48Questions: 14Answers: 1

It would be nice to have a public function to reset multiValue fields to their initial state, or more generally a function to reset any field to its initial state.

Context:

We have a from with checkbox fields A, B, ..., and dependent fields A1, A2, B1, `B2,...
The child fields are only shown when the parent checkbox is on.
We would like to do the following when multiple rows are edited: (the problem is in the third item)

  • If all rows have A checked, show A1, A2 as normal fields, with the usual multiValue behavior. When A is unchecked, the child fields are hidden. (Their value is cleared at the server, so this is fine.)
  • If none of the rows have A checked, the child fields will be shown when A is clicked. All child fields start empty, so the normal behavior works well.
  • If A is a multiValue, the child fields are hidden initially. When A is checked, the children are shown. Their default multiValue behavior is used. (so far so good) Now, when A is reverted by clicking undo changes, I would like to revert the child fields to their initial state as well, but I don't see how to do this in a nice way. Some of the child fields could be in a multiValue state, so calling the private multiReturn.on('click') function would work, but some might be non-multiValue fields, and I don't know of a way to change those back to their initial state.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    That's interesting - thank you. I hadn't included this ability because I figured that if you were using the API you wouldn't be using the UI for the multi-row editing at the same time. Obviously that isn't the case with your use case.

    I can't promise anything as there is a significant feature back log at the moment, but I will look into implementing this. Thanks for the suggestion.

    Regards,
    Allan

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Just a quick thought - perhaps another option would be to read the existing values from the table and use the API to set those values when the event occurs.

    Allan

  • RagnarGrootKoerkampRagnarGrootKoerkamp Posts: 48Questions: 14Answers: 1
    edited August 2016

    Resetting values by reading them from the table should work well indeed. Thanks!

    This will still require a custom event when Undo Changes is clicked, but that should be easy to implement myself.

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    Just a quick update here in case anyone else finds this - I've added field().multiRestore() to the Editor API which will be available in 1.7.

    Regards,
    Allan

This discussion has been closed.