Skip to content

Commit

Permalink
Fix rename scenario for Internet Explorer
Browse files Browse the repository at this point in the history
Using _.curry appeared to call the validate function before it needed to
be called, which resulted in a JS error and prevented the modal from
being displayed. Keeping the correct scope for the validate function is
slightly reworked here so that _.curry does not need to be used, which
lets things work as expected in IE.

Refs #2315
  • Loading branch information
caseycesari committed Oct 3, 2017
1 parent 08d314a commit 47ea814
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/mmw/js/src/modeling/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -977,20 +977,20 @@ var ScenariosCollection = Backbone.Collection.extend({
},

/** Validate the new scenario name
@param model - the model your trying to rename
The value of *this* is the scenario model.
@param newName the new name string
@returns If valid, null
If invalid, a string with the error
**/
validateNewScenarioName: function(model, newName) {
validateNewScenarioName: function(newName) {
var trimmedNewName = newName.trim();

// Bail early if the name actually didn't change.
if (model.get('name') === trimmedNewName) {
if (this.get('name') === trimmedNewName) {
return null;
}

var match = this.find(function(model) {
var match = this.collection.find(function(model) {
return model.get('name').toLowerCase() === trimmedNewName.toLowerCase();
});

Expand Down
5 changes: 2 additions & 3 deletions src/mmw/js/src/modeling/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,13 @@ var ScenarioDropDownMenuOptionsView = Marionette.ItemView.extend({
renameScenario: function() {
var self = this,
collection = self.model.collection,
validate = _.bind(collection.validateNewScenarioName, collection),
curriedValidationFunction = _.curry(validate)(this.model),
validate = _.bind(collection.validateNewScenarioName, self.model),
rename = new modalViews.InputView({
model: new modalModels.InputModel({
initial: this.model.get('name'),
title: 'Rename Scenario',
fieldLabel: 'Scenario Name',
validationFunction: curriedValidationFunction,
validationFunction: validate,
})
});

Expand Down

0 comments on commit 47ea814

Please sign in to comment.