Last active
January 7, 2022 15:04
-
-
Save vfontjr/bff226e0fa03bfcf48d7c900132c4184 to your computer and use it in GitHub Desktop.
This file contains 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
<script> | |
jQuery(document).ready(function($) { | |
"use strict"; | |
// populate primary contact name and email from registration credentials | |
$("#field_devdir_copy_name_and_email").on("change", function() { | |
if ( $(this).prop('checked') ) { | |
bindCurrent(); | |
} else { | |
unbindCurrent(); | |
} | |
}); | |
var bindCurrent = function() { | |
// First copy values | |
$("#field_devdir_primary_contact_first").val($("#field_devdir_first_name").val()).attr("readonly",true); //first name | |
$("#field_devdir_primary_contact_last").val($("#field_devdir_last_name").val()).attr("readonly",true); // last name | |
$("#field_devdir_primary_contact_email").val($("#field_devdir_email").val()).attr("readonly",true); // email | |
/* Then bind fields */ | |
/* first name */ | |
$("#field_devdir_first_name").keyup(function() { | |
$("#field_devdir_primary_contact_first").val($(this).val()); | |
}); | |
/* last name */ | |
$("#field_devdir_last_name").keyup(function() { | |
$("#field_devdir_primary_contact_last").val($(this).val()); | |
}); | |
/* email */ | |
$("#field_devdir_email").keyup(function() { | |
$("#field_devdir_primary_contact_email").val($(this).val()); | |
}); | |
}; | |
var unbindCurrent = function() { | |
/* unbind fields */ | |
$("#field_devdir_first_name").unbind("keyup"); | |
$("#field_devdir_last_name").unbind("keyup"); | |
$("#field_devdir_email").unbind("keyup"); | |
/* clear readonly and disabled attributes */ | |
$("#field_devdir_primary_contact_first").removeAttr("readonly"); | |
$("#field_devdir_primary_contact_last").removeAttr("readonly"); | |
$("#field_devdir_primary_contact_email").removeAttr("readonly"); | |
/* clear fields of copied values */ | |
$("#field_devdir_primary_contact_first").val(""); | |
$("#field_devdir_primary_contact_last").val(""); | |
$("#field_devdir_primary_contact_email").val(""); | |
/* set focus to primary contact first name */ | |
$("#field_devdir_primary_contact_first").focus(); | |
}; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment