Do not try to submit if we already know the name is invalid

master
Daniel Berteaud 11 years ago
parent 5f01424bb5
commit 0686bed1e8
  1. 52
      public/js/vroom.js

@ -236,30 +236,36 @@ function initIndex(){
// Submit the main form to create a room
$('#createRoom').submit(function(e){
e.preventDefault();
$.ajax({
url: rootUrl + 'create',
type: 'POST',
dataType: 'json',
data: {
roomName: $('#roomName').val(),
},
success: function(data) {
if (data.status == 'success'){
room = data.room;
window.location.assign(rootUrl + data.room);
}
else if (data.err && data.err == 'ERROR_NAME_CONFLICT' ){
room = data.room;
$('#conflictModal').modal('show');
}
else{
$('#roomName').notify(data.msg, 'error');
// Do not submit if we know the name is invalid
if (!$('#roomName').val().match(/^[\w\-]{0,49}$/)){
$('#roomName').notify('ERROR_NAME_INVALID', 'error');
}
else{
$.ajax({
url: rootUrl + 'create',
type: 'POST',
dataType: 'json',
data: {
roomName: $('#roomName').val(),
},
success: function(data) {
if (data.status == 'success'){
room = data.room;
window.location.assign(rootUrl + data.room);
}
else if (data.err && data.err == 'ERROR_NAME_CONFLICT' ){
room = data.room;
$('#conflictModal').modal('show');
}
else{
$('#roomName').notify(data.msg, 'error');
}
},
error: function(){
$.notify(locale.ERROR_OCCURRED, 'error');
}
},
error: function(){
$.notify(locale.ERROR_OCCURRED, 'error');
}
});
});
}
});
// Handle join confirmation

Loading…
Cancel
Save