Reorder multifield items through javascript | Community
Skip to main content
New Participant
January 30, 2023
Solved

Reorder multifield items through javascript

  • January 30, 2023
  • 1 reply
  • 1087 views

Hi Team,

 

I have a multifield with 2 fields in which one is date field, On the dialog submit  I want to reorder multifield items based on date (oldest date item should show first and it should also store at the jcr node)

 

Example:

 

item0 => date : 01/01/1998
              name : John

item1 => date : 01/01/1995
             name : Ram

item2 => date : 01/01/1990
             name : shyam

 


When I reopen dialog , The oldest date item should show first like below

 

item0 => date : 01/01/1990
            name : shyam

item1 => date : 01/01/1995
           name : Ram

item2 => date : 01/01/1998
          name : John

 

 

Thanks in advance

 

 




This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

Hi Arun, Thanks for your response. I would like to know, Is there any event listener for dialog submit and can modify the payload to reorder items.?


yes, there is

 

$(document).on("click", ".cq-dialog-submit", function (e) { //$(window).adaptTo("foundation-ui").alert("Close", "Dialog closed, selector [.cq-dialog-submit]"); });

 or

$document.on("dialog-success", function() { //$(window).adaptTo("foundation-ui").alert("Save", "Dialog content saved, event [dialog-success]"); });

1 reply

arunpatidar
New Participant
January 30, 2023

on dialog submit click event you need to reorder multifield item in HTML DOM.

Arun Patidar
gskittuAuthor
New Participant
January 30, 2023

Thanks Arun, Yes need to reorder elements in DOM, I need help with javascript to reorder html elements 

arunpatidar
New Participant
January 30, 2023

var
wrapper = $('multifield'), items = wrapper.children('multifield-item'), arr = [2,1,0]; wrapper.append( $.map(arr, function(v){ return items[v] }) );

This is just an example, there are more

https://stackoverflow.com/questions/34685316/reorder-html-elements-in-dom 

https://www.benjaminrancourt.ca/how-to-sort-divs-based-on-contents/ 

Arun Patidar