Skip to content

Commit 1875ff2

Browse files
committed
Fix add new must attrs to RDN select. Fixes #382
1 parent 392d513 commit 1875ff2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

resources/views/components/attribute/widget/options.blade.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ function process_oc() {
8686
success: function(data) {
8787
// Render any must attributes
8888
if (data.must.length) {
89+
var newattr = $('select#rdn');
90+
var oldoptions = $('select#rdn option').map((i,o)=>o.value).get();
91+
8992
data.must.forEach(function(item) {
9093
if ($('attribute#'+item.toLowerCase()).length)
9194
return;
@@ -107,6 +110,21 @@ function process_oc() {
107110
alert('That didnt work? Please try again....');
108111
},
109112
});
113+
114+
// If this is a new entry, add the required attributes to the RDN
115+
if (! oldoptions.includes(item))
116+
newattr.append(new Option(item,item,false,false));
117+
118+
// Sort the attributes
119+
newattr
120+
.append($('select#rdn option')
121+
.remove()
122+
.sort(function (a,b) {
123+
let at = $(a).text(),
124+
bt = $(b).text();
125+
return (at > bt) ? 1 : ((at < bt) ? -1 : 0);
126+
}))
127+
.val('');
110128
})
111129
}
112130

0 commit comments

Comments
 (0)