Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This functionality allows for us to create an input that updates a link/piece of text/etc. [Finishes #119563151]
- Loading branch information
1 parent
70de802
commit e19dcb2
Showing
5 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
exports.stepper = require('./stepper'); | ||
exports.linkUpdater = require('./link-updater'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
var $ = require('jquery'); | ||
var isInvalid = require('npm-user-validate').username; | ||
|
||
var LinkUpdater = function(el){ | ||
this.el = $(el); | ||
this.input = this.el.find("input"); | ||
this.pathDisplay = this.el.find("p strong"); | ||
this.currentValue = ""; | ||
}; | ||
|
||
LinkUpdater.prototype.updateValue = function(inputValue){ | ||
var pathVal = inputValue; | ||
if(inputValue === ""){ | ||
pathVal = "username"; | ||
} | ||
this.currentValue = inputValue; | ||
this.pathDisplay.text(pathVal); | ||
}; | ||
|
||
LinkUpdater.prototype.showError = function(msg){ | ||
var err = this.el.find(".error"); | ||
|
||
if(!err.length) { | ||
err = $("<span />") | ||
.addClass("error") | ||
.text(msg); | ||
|
||
this.el.append(err); | ||
} else { | ||
err.text(msg); | ||
} | ||
|
||
}; | ||
|
||
LinkUpdater.prototype.hideError = function(){ | ||
this.el.find(".error").remove(); | ||
}; | ||
|
||
$(function(){ | ||
var linkUpdater = $(".link-updater"); | ||
|
||
$.each(linkUpdater, function(idx, el){ | ||
var lu = new LinkUpdater(el); | ||
|
||
lu.input.on("input", function(e){ | ||
var err = isInvalid(e.target.value); | ||
if(err) { | ||
e.target.value = lu.currentValue; | ||
lu.showError(err.message); | ||
} else { | ||
lu.hideError(); | ||
lu.updateValue(e.target.value); | ||
} | ||
}); | ||
|
||
}); | ||
}); | ||
|
||
module.exports = LinkUpdater; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters