Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Reorder multifield items through javascript

Avatar

Level 2

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

 

gskittu_0-1675079650908.png

 

Thanks in advance

 

 




1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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]");
    });


Arun Patidar

View solution in original post

5 Replies

Avatar

Community Advisor

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



Arun Patidar

Avatar

Level 2

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

Avatar

Community Advisor

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

Avatar

Level 2

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.?

Avatar

Correct answer by
Community Advisor

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]");
    });


Arun Patidar