Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
disable "Validate" button until URL is wellformed (bug 731131)
Browse files Browse the repository at this point in the history
  • Loading branch information
cvan committed Feb 28, 2012
1 parent 473acbc commit d7ed67c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions media/js/devreg/devhub.js
Expand Up @@ -50,7 +50,9 @@ $(document).ready(function() {
if($('#upload-webapp-url').exists()) {
$('#upload-webapp-url').bind("keyup change paste blur", function(e) {
var $this = $(this),
$button = $('#validate_app');
$button = $('#validate_app'),
// Ensure it's at least "protocol://host/something".
match = $this.val().match(/^(.+):\/\/(.+)/);

This comment has been minimized.

Copy link
@robhudson

robhudson Feb 28, 2012

Member

Aren't you creating a copy of the regular expression on each key press? Is that expensive? Why not pull that out and into a var? var regexp = /^(.+):\/\/(.+)/; and then $this.val().match(regexp)?

This comment has been minimized.

Copy link
@cvan

cvan Feb 28, 2012

Author Contributor

because @gkoberger originally wrote that code, and I didn't notice that. good catch!

This comment has been minimized.

Copy link
@robhudson

robhudson Feb 28, 2012

Member

This regex will pass with something like "http://a". Is that good enough? The comment is a bit misleading.


if($this.attr('data-input') != $this.val()) {
// Show warning if 8+ characters have been typed but there's no protocol.
Expand All @@ -62,9 +64,9 @@ $(document).ready(function() {
.parent().removeClass('show-tip');
}

if ($this.val()) {
$button.removeClass('disabled'); // show validate btn
}
// Show the button if valid.
$button.toggleClass('disabled', !match);

$this.attr('data-input', $this.val());
$('#upload-status-results').remove();
$('#upload-file button.upload-file-submit').attr('disabled', true);
Expand Down

0 comments on commit d7ed67c

Please sign in to comment.