Skip to content

Commit aa55f43

Browse files
committed
added validation. close goodybag#3
1 parent c5cbece commit aa55f43

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

chrome/main.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ var trelloGithub = (function($, Trello) {
7272
}
7373

7474
var createIssue = exports.createIssue = function(event) {
75+
if (!['#github-repo', '#issue-title'].map(function(e){return validate(e);}).reduce(function(p, c, i, a){return p&&c;}, true))
76+
return;
77+
7578
var pathparts = location.pathname.split('/');
7679
var boardId = pathparts[pathparts.length - 2];
7780
var cardShortId = pathparts[pathparts.length - 1];
@@ -85,7 +88,8 @@ var trelloGithub = (function($, Trello) {
8588

8689
Trello.post('/checklists/' + checklist.id + '/checkItems', {name:issue.html_url}, function() {
8790
//hooray! we've completed everything.
88-
window.location.reload();
91+
$('#github-popover').hide();
92+
//window.location.reload();
8993
}, function() {
9094
alert('trello api error');
9195
});
@@ -151,9 +155,39 @@ var trelloGithub = (function($, Trello) {
151155
}
152156
});
153157
$('.js-create-github-issue').click(createIssue);
158+
159+
//validation
160+
$('#issue-title').blur(function(e){
161+
validate('#issue-title');
162+
});
163+
164+
$('#github-repo').blur(function(e) {
165+
validate('#github-repo')
166+
});
154167
});
155168
}
156169

170+
var validators = {
171+
'#github-repo':function(){
172+
var good = (/^[^\s\/]+\/[^\s\/]+$/.test($('#github-repo').val()));
173+
$('#github-repo').toggleClass('input-error', !good);
174+
return good;
175+
},
176+
'#issue-title':function(){
177+
var good = $('#issue-title').val().length > 0;
178+
$('#issue-title').toggleClass('input-error', !good);
179+
return good;
180+
}
181+
};
182+
183+
var validate = exports.validate = function(id) {
184+
var validator = validators[id];
185+
if (typeof validator !== 'function')
186+
return null;
187+
188+
return validator();
189+
}
190+
157191
setupPopover();
158192
githubAuth();
159193

0 commit comments

Comments
 (0)