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

Loading…
Cancel
Save