Initial stab URL validation. Adding '*' to label is now done via CSS :before rather than jquery DOM manipulation.

This commit is contained in:
chouseknecht
2013-09-11 16:44:17 -04:00
parent 39ceceb18e
commit 55292c9d08
4 changed files with 19 additions and 13 deletions

View File

@@ -97,7 +97,15 @@ angular.module('ProjectFormDefinition', [])
type: 'text', type: 'text',
ngShow: "scm_type !== '' && scm_type !== null", ngShow: "scm_type !== '' && scm_type !== null",
awValidUrl: true, awValidUrl: true,
awRequiredWhen: {variable: "scm_type", init: "true" } awRequiredWhen: { variable: "scm_type", init: "true" },
awPopOver: "<p>Provide the URL to your SCM server. The value should begin with the protocol https:\/\/, http:\/\/ or ssh:\/\/.</p>" +
"<p>Do not inlcude username or password values. Use the authentication settings instead.</p>" +
"<p>Examples include:</p>" +
"<p>ssh:\/\/github.com:ansible/ansible-examples.git</p>" +
"<p>https:\/\/github.com/ansible/ansible-examples.git</p>",
dataTitle: 'SCM URL',
dataPlacement: 'right',
dataContainer: 'body'
}, },
scm_branch: { scm_branch: {
labelBind: "scmBranchLabel", labelBind: "scmBranchLabel",

View File

@@ -48,6 +48,10 @@ body {
} }
} }
.prepend-asterisk:before {
content: "\002A";
}
.subtitle { .subtitle {
font-size: 16px; font-size: 16px;
} }

View File

@@ -112,26 +112,21 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Hos
if ( scope[attrs.awRequiredWhen] && (elm.attr('required') == null || elm.attr('required') == undefined) ) { if ( scope[attrs.awRequiredWhen] && (elm.attr('required') == null || elm.attr('required') == undefined) ) {
$(elm).attr('required','required'); $(elm).attr('required','required');
if ($(elm).hasClass('lookup')) { if ($(elm).hasClass('lookup')) {
$(elm).parent().parent().parent().find('label').prepend('* '); $(elm).parent().parent().parent().find('label').addClass('prepend-asterisk');
} }
else { else {
$(elm).parent().parent().find('label').prepend('* '); $(elm).parent().parent().find('label').addClass('prepend-asterisk');
} }
} }
else if (!scope[attrs.awRequiredWhen]) { else if (!scope[attrs.awRequiredWhen]) {
elm.removeAttr('required'); elm.removeAttr('required');
if ($(elm).hasClass('lookup')) { if ($(elm).hasClass('lookup')) {
txt = $(elm).parent().parent().parent().find('label').text();
label = $(elm).parent().parent().parent().find('label'); label = $(elm).parent().parent().parent().find('label');
} }
else { else {
txt = $(elm).parent().parent().find('label').text();
label = $(elm).parent().parent().find('label'); label = $(elm).parent().parent().find('label');
} }
txt = txt.replace(/^\* /,''); label.removeClass('prepend-asterisk');
if (label) {
label.text(txt);
}
} }
if (scope[attrs.awRequiredWhen] && (viewValue == undefined || viewValue == null || viewValue == '')) { if (scope[attrs.awRequiredWhen] && (viewValue == undefined || viewValue == null || viewValue == '')) {
validity = false; validity = false;

View File

@@ -92,10 +92,9 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies'])
// Prepend an asterisk to required field label // Prepend an asterisk to required field label
$('.form-control[required]').each(function() { $('.form-control[required]').each(function() {
var label = $(this).parent().parent().find('label'); var label = $(this).parent().parent().find('label');
var rgx = /^\*/; if (label && !label.hasClass('prepend-asterisk')) {
if ( !rgx.test(label.text()) ) { console.log('adding prepend');
// required field does not have leading * label.addClass('prepend-asterisk');
label.prepend('* ');
} }
}); });