Skip to content

Instantly share code, notes, and snippets.

@philipmadeley
Last active September 16, 2015 02:00
Show Gist options
  • Select an option

  • Save philipmadeley/f72b7ff73893eb74d035 to your computer and use it in GitHub Desktop.

Select an option

Save philipmadeley/f72b7ff73893eb74d035 to your computer and use it in GitHub Desktop.
Function for input fields
$(document).ready( function(){
$('.save-button').on('click', save_onclick);
$('.cancel-button').on('click', cancel_onclick);
$('.edit-button').on('click', edit_onclick);
$('.save-button, .cancel-button').hide();
});
function edit_onclick(){
setFormMode($(this).closest("form"), 'edit');
}
function cancel_onclick(){
setFormMode($(this).closest("form"), 'view');
//TODO: Undo input changes?
}
function save_onclick(){
setFormMode($(this).closest("form"), 'view');
//TODO: Send data to server?
}
function setFormMode($form, mode){
switch(mode){
case 'view':
$form.find('.save-button, .cancel-button').hide();
$form.find('.edit-button').show();
$form.find("input, select").prop("disabled", true);
break;
case 'edit':
$form.find('.save-button, .cancel-button').show();
$form.find('.edit-button').hide();
$form.find("input, select").prop("disabled", false);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment