Commit cfd5bafc authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1681588: Fixing up jQuery for add email address field



Also adding a basic check that the text supplied has at least:
 one @ and one .

Also fixed the problem with delete button still using a MochiKit
function

 behatnotneeded

Change-Id: I395cbb4f23326dca179e46d0116d43f64aed9615
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 703af39e
......@@ -475,6 +475,7 @@ $smarty = smarty(array(), array(), array(
'mahara' => array(
'cannotremovedefaultemail',
'emailtoolong',
'emailinvalid',
'tabs',
'tab',
'selected',
......
......@@ -449,6 +449,7 @@ $string['yournewpasswordagain'] = 'Your new password again';
$string['invalidsesskey'] = 'Invalid session key';
$string['cannotremovedefaultemail'] = 'You cannot remove your primary email address.';
$string['emailtoolong'] = 'Email addresses cannot be longer than 255 characters.';
$string['emailinvalid'] = 'Email address invalid.';
$string['mustspecifyoldpassword'] = 'You must specify your current password.';
$string['Site'] = 'Site';
$string['maildisabled'] = 'Email disabled';
......
......@@ -20,15 +20,18 @@
var {{$name}}_newref = null;
function {{$name}}_addedemail() {
jQuery("#{{$name}}_newrefinput").remove();
jQuery("#{{$name}}_newref").remove();
var newEmail = {{$name}}_newrefinput.value;
// Are jQuery objects here so can deal with them directly
var newEmail = {{$name}}_newrefinput.val();
if (typeof(newEmail) == 'string' && newEmail.length > 0) {
if (newEmail.length > 255) {
alert(get_string('emailtoolong'));
}
else if (newEmail.indexOf("@") == -1 || newEmail.indexOf(".") == -1) {
alert(get_string('emailinvalid'));
}
else {
var email = {{$name}}_newrefinput.value;
var email = newEmail;
jQuery('#{{$name}}_list').append(jQuery('<div>', {'class': 'unsent'}).append(
jQuery('<input>', {'type': 'hidden', 'name': '{{$name}}_unsent[]' , 'value': email}),
' ',
......@@ -43,10 +46,12 @@
var form = jQuery(this).closest('form')[0];
formchangemanager.setFormState(form, FORM_CHANGED);
}
{{$name}}_newrefinput.remove();
{{$name}}_newref.remove();
{{$name}}_newrefinput = null;
{{$name}}_newref = null;
}
}
{{$name}}_newrefinput = null;
{{$name}}_newref = null;
}
function {{$name}}_new() {
......@@ -77,14 +82,11 @@
}
function {{$name}}_remove(x) {
var div = x.parentNode;
var radio = filter(
function(elem) { return jQuery(elem).prop('type') === 'radio'; },
jQuery(div).find('input')
);
var delbtn = jQuery(x);
var div = delbtn.closest('div');
var radio = div.find('[type=radio]');
if (radio[0] && radio[0].checked) {
if (radio.length && radio.is(':checked')) {
alert(get_string('cannotremovedefaultemail'));
return;
}
......@@ -94,7 +96,7 @@
formchangemanager.setFormState(form, FORM_CHANGED);
}
jQuery(x.parentNode).remove();
div.remove();
}
</script>
<div id="{{$name}}_list" class="{{$name}}-list email-list">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment