Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug #525 - optimise rendering of select options. #528

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/editors/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ Form.editors.Select = Form.editors.Base.extend({
* @return {String} HTML
*/
_arrayToHtml: function(array) {
var html = $();
var html = [];

//Generate HTML
_.each(array, function(option) {
Expand All @@ -221,18 +221,18 @@ Form.editors.Select = Form.editors.Base.extend({
var optgroup = $("<optgroup>")
.attr("label",option.group)
.html( this._getOptionsHtml(option.options) );
html = html.add(optgroup);
html[html.length] = optgroup[0];
Copy link
Collaborator

@philfreo philfreo Oct 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not say html.push(optgroup[0])?

} else {
var val = (option.val || option.val === 0) ? option.val : '';
html = html.add( $('<option>').val(val).text(option.label) );
html[html.length] = $('<option>').val(val).text(option.label)[0];
}
}
else {
html = html.add( $('<option>').text(option) );
html[html.length] = $('<option>').text(option)[0];
}
}, this);

return html;
return $().add(html);
}

});
23 changes: 23 additions & 0 deletions test/editors/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,29 @@
equal(newOptions.last().html(), 'Phil');
});


test('Rendering: Only adds options to the DOM with one function call ', function() {
var options = [],
length = 4000;

for(var i = 0;i < length;i++) {
options.push('option-' + i);
}

var editor = new Editor({
schema: {
options: options
}
});

var spy = sinon.spy($.fn, 'add');

editor.render();

equal(spy.callCount, 1);

});

test("setValue() - updates the input value", function() {
var editor = new Editor({
value: 'Pam',
Expand Down