Last active
September 16, 2015 02:00
-
-
Save philipmadeley/f72b7ff73893eb74d035 to your computer and use it in GitHub Desktop.
Function for input fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(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