values are now visible in text field
on selecting an option, emails will be displayed in the field
This commit is contained in:
parent
6cc2efd925
commit
2141993b28
1 changed files with 23 additions and 1 deletions
|
|
@ -7,7 +7,7 @@
|
|||
.panel-body
|
||||
%p
|
||||
%b Select/Enter Emails
|
||||
= text_field_tag :to, '', class: 'form-control', id: 'admin_email_to'
|
||||
= text_field_tag :to, '', class: 'form-control', id: 'admin_email_to', data: { keys: @keys }
|
||||
%br
|
||||
%p.text-right
|
||||
= link_to 'Send Email', '', class: 'btn btn-primary'
|
||||
|
|
@ -31,4 +31,26 @@
|
|||
}
|
||||
}
|
||||
})
|
||||
var selectizeControl = $select[0].selectize;
|
||||
var email_hash = $('#admin_email_to').data('keys')
|
||||
for(var key in email_hash){
|
||||
selectizeControl.addOption({item: key});
|
||||
}
|
||||
selectizeControl.on('change', function() {
|
||||
var emails_in_to_field = selectizeControl.getValue();
|
||||
if (emails_in_to_field==''){
|
||||
selectizeControl.clearOptions();
|
||||
for(var key in email_hash){
|
||||
selectizeControl.addOption({item: key});
|
||||
}
|
||||
} else if (emails_in_to_field in email_hash){
|
||||
for (var i = 0, n = email_hash[emails_in_to_field].length; i < n; i++) {
|
||||
selectizeControl.addOption({item: email_hash[emails_in_to_field][i]});
|
||||
}
|
||||
selectizeControl.setValue(email_hash[emails_in_to_field]);
|
||||
selectizeControl.clearOptions();
|
||||
} else {
|
||||
selectizeControl.refreshOptions();
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue