mirror of
https://github.com/ansible/awx.git
synced 2026-05-15 13:27:40 -02:30
Wraps label count validation in function
This commit is contained in:
@@ -496,45 +496,50 @@
|
|||||||
$state.transitionTo('templates');
|
$state.transitionTo('templates');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
let handleLabelCount = () => {
|
||||||
* This block of code specifically handles the client-side validation of the `labels` field.
|
/**
|
||||||
* Due to it's detached nature in relation to the other job template fields, we must
|
* This block of code specifically handles the client-side validation of the `labels` field.
|
||||||
* validate this field client-side in order to avoid the edge case where a user can make a
|
* Due to it's detached nature in relation to the other job template fields, we must
|
||||||
* successful POST to the `job_templates` endpoint but however encounter a 200 error from
|
* validate this field client-side in order to avoid the edge case where a user can make a
|
||||||
* the `labels` endpoint due to a character limit.
|
* successful POST to the `job_templates` endpoint but however encounter a 200 error from
|
||||||
*
|
* the `labels` endpoint due to a character limit.
|
||||||
* We leverage two of select2's available events, `select` and `unselect`, to detect when the user
|
*
|
||||||
* has either added or removed a label. From there, we set a flag and do simple string length
|
* We leverage two of select2's available events, `select` and `unselect`, to detect when the user
|
||||||
* checks to make sure a label's chacacter count remains under 512. Otherwise, we disable the "Save" button
|
* has either added or removed a label. From there, we set a flag and do simple string length
|
||||||
* by invalidating the field and inform the user of the error.
|
* checks to make sure a label's chacacter count remains under 512. Otherwise, we disable the "Save" button
|
||||||
*/
|
* by invalidating the field and inform the user of the error.
|
||||||
|
*/
|
||||||
|
|
||||||
$scope.job_template_labels_isValid = true;
|
|
||||||
const maxCount = 512;
|
|
||||||
const jt_label_id = 'job_template_labels';
|
|
||||||
|
|
||||||
// Detect when a new label is added
|
$scope.job_template_labels_isValid = true;
|
||||||
$(`#${jt_label_id}`).on('select2:select', (e) => {
|
|
||||||
const { text } = e.params.data;
|
|
||||||
|
|
||||||
// If the character count of an added label is greater than 512, we set `labels` field as invalid
|
|
||||||
if (text.length > maxCount) {
|
|
||||||
$scope.job_template_form.labels.$setValidity(`${jt_label_id}`, false);
|
|
||||||
$scope.job_template_labels_isValid = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Detect when a label is removed
|
|
||||||
$(`#${jt_label_id}`).on('select2:unselect', (e) => {
|
|
||||||
const maxCount = 512;
|
const maxCount = 512;
|
||||||
const { text } = e.params.data;
|
const jt_label_id = 'job_template_labels';
|
||||||
|
|
||||||
/* If the character count of a removed label is greater than 512 AND the field is currently marked
|
// Detect when a new label is added
|
||||||
as invalid, we set it back to valid */
|
$(`#${jt_label_id}`).on('select2:select', (e) => {
|
||||||
if (text.length > maxCount && $scope.job_template_form.labels.$error) {
|
const { text } = e.params.data;
|
||||||
$scope.job_template_form.labels.$setValidity(`${jt_label_id}`, true);
|
|
||||||
$scope.job_template_labels_isValid = true;
|
// If the character count of an added label is greater than 512, we set `labels` field as invalid
|
||||||
}
|
if (text.length > maxCount) {
|
||||||
});
|
$scope.job_template_form.labels.$setValidity(`${jt_label_id}`, false);
|
||||||
|
$scope.job_template_labels_isValid = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Detect when a label is removed
|
||||||
|
$(`#${jt_label_id}`).on('select2:unselect', (e) => {
|
||||||
|
const maxCount = 512;
|
||||||
|
const { text } = e.params.data;
|
||||||
|
|
||||||
|
/* If the character count of a removed label is greater than 512 AND the field is currently marked
|
||||||
|
as invalid, we set it back to valid */
|
||||||
|
if (text.length > maxCount && $scope.job_template_form.labels.$error) {
|
||||||
|
$scope.job_template_form.labels.$setValidity(`${jt_label_id}`, true);
|
||||||
|
$scope.job_template_labels_isValid = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
handleLabelCount();
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -705,45 +705,49 @@ export default
|
|||||||
$state.go('templates');
|
$state.go('templates');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
let handleLabelCount = () => {
|
||||||
* This block of code specifically handles the client-side validation of the `labels` field.
|
/**
|
||||||
* Due to it's detached nature in relation to the other job template fields, we must
|
* This block of code specifically handles the client-side validation of the `labels` field.
|
||||||
* validate this field client-side in order to avoid the edge case where a user can make a
|
* Due to it's detached nature in relation to the other job template fields, we must
|
||||||
* successful POST to the `job_templates` endpoint but however encounter a 200 error from
|
* validate this field client-side in order to avoid the edge case where a user can make a
|
||||||
* the `labels` endpoint due to a character limit.
|
* successful POST to the `job_templates` endpoint but however encounter a 200 error from
|
||||||
*
|
* the `labels` endpoint due to a character limit.
|
||||||
* We leverage two of select2's available events, `select` and `unselect`, to detect when the user
|
*
|
||||||
* has either added or removed a label. From there, we set a flag and do simple string length
|
* We leverage two of select2's available events, `select` and `unselect`, to detect when the user
|
||||||
* checks to make sure a label's chacacter count remains under 512. Otherwise, we disable the "Save" button
|
* has either added or removed a label. From there, we set a flag and do simple string length
|
||||||
* by invalidating the field and inform the user of the error.
|
* checks to make sure a label's chacacter count remains under 512. Otherwise, we disable the "Save" button
|
||||||
*/
|
* by invalidating the field and inform the user of the error.
|
||||||
|
*/
|
||||||
|
|
||||||
$scope.job_template_labels_isValid = true;
|
$scope.job_template_labels_isValid = true;
|
||||||
const maxCount = 512;
|
|
||||||
const jt_label_id = 'job_template_labels';
|
|
||||||
|
|
||||||
// Detect when a new label is added
|
|
||||||
$(`#${jt_label_id}`).on('select2:select', (e) => {
|
|
||||||
const { text } = e.params.data;
|
|
||||||
|
|
||||||
// If the character count of an added label is greater than 512, we set `labels` field as invalid
|
|
||||||
if (text.length > maxCount) {
|
|
||||||
$scope.job_template_form.labels.$setValidity(`${jt_label_id}`, false);
|
|
||||||
$scope.job_template_labels_isValid = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Detect when a label is removed
|
|
||||||
$(`#${jt_label_id}`).on('select2:unselect', (e) => {
|
|
||||||
const maxCount = 512;
|
const maxCount = 512;
|
||||||
const { text } = e.params.data;
|
const jt_label_id = 'job_template_labels';
|
||||||
|
|
||||||
/* If the character count of a removed label is greater than 512 AND the field is currently marked
|
// Detect when a new label is added
|
||||||
as invalid, we set it back to valid */
|
$(`#${jt_label_id}`).on('select2:select', (e) => {
|
||||||
if (text.length > maxCount && $scope.job_template_form.labels.$error) {
|
const { text } = e.params.data;
|
||||||
$scope.job_template_form.labels.$setValidity(`${jt_label_id}`, true);
|
|
||||||
$scope.job_template_labels_isValid = true;
|
// If the character count of an added label is greater than 512, we set `labels` field as invalid
|
||||||
}
|
if (text.length > maxCount) {
|
||||||
});
|
$scope.job_template_form.labels.$setValidity(`${jt_label_id}`, false);
|
||||||
|
$scope.job_template_labels_isValid = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Detect when a label is removed
|
||||||
|
$(`#${jt_label_id}`).on('select2:unselect', (e) => {
|
||||||
|
const maxCount = 512;
|
||||||
|
const { text } = e.params.data;
|
||||||
|
|
||||||
|
/* If the character count of a removed label is greater than 512 AND the field is currently marked
|
||||||
|
as invalid, we set it back to valid */
|
||||||
|
if (text.length > maxCount && $scope.job_template_form.labels.$error) {
|
||||||
|
$scope.job_template_form.labels.$setValidity(`${jt_label_id}`, true);
|
||||||
|
$scope.job_template_labels_isValid = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
handleLabelCount();
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -179,41 +179,45 @@ export default [
|
|||||||
$state.transitionTo('templates');
|
$state.transitionTo('templates');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
let handleLabelCount = () => {
|
||||||
* This block of code specifically handles the client-side validation of the `labels` field.
|
/**
|
||||||
* Due to it's detached nature in relation to the other job template fields, we must
|
* This block of code specifically handles the client-side validation of the `labels` field.
|
||||||
* validate this field client-side in order to avoid the edge case where a user can make a
|
* Due to it's detached nature in relation to the other job template fields, we must
|
||||||
* successful POST to the `workflow_job_templates` endpoint but however encounter a 200 error from
|
* validate this field client-side in order to avoid the edge case where a user can make a
|
||||||
* the `labels` endpoint due to a character limit.
|
* successful POST to the `workflow_job_templates` endpoint but however encounter a 200 error from
|
||||||
*
|
* the `labels` endpoint due to a character limit.
|
||||||
* We leverage two of select2's available events, `select` and `unselect`, to detect when the user
|
*
|
||||||
* has either added or removed a label. From there, we set a flag and do simple string length
|
* We leverage two of select2's available events, `select` and `unselect`, to detect when the user
|
||||||
* checks to make sure a label's chacacter count remains under 512. Otherwise, we disable the "Save" button
|
* has either added or removed a label. From there, we set a flag and do simple string length
|
||||||
* by invalidating the field and inform the user of the error.
|
* checks to make sure a label's chacacter count remains under 512. Otherwise, we disable the "Save" button
|
||||||
*/
|
* by invalidating the field and inform the user of the error.
|
||||||
|
*/
|
||||||
|
|
||||||
$scope.workflow_job_template_labels_isValid = true;
|
$scope.workflow_job_template_labels_isValid = true;
|
||||||
const maxCount = 512;
|
|
||||||
const wfjt_label_id = 'workflow_job_template_labels';
|
|
||||||
// Detect when a new label is added
|
|
||||||
$(`#${wfjt_label_id}`).on('select2:select', (e) => {
|
|
||||||
const { text } = e.params.data;
|
|
||||||
// If the character count of an added label is greater than 512, we set `labels` field as invalid
|
|
||||||
if (text.length > maxCount) {
|
|
||||||
$scope.workflow_job_template_form.labels.$setValidity(`${wfjt_label_id}`, false);
|
|
||||||
$scope.workflow_job_template_labels_isValid = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Detect when a label is removed
|
|
||||||
$(`#${wfjt_label_id}`).on('select2:unselect', (e) => {
|
|
||||||
const maxCount = 512;
|
const maxCount = 512;
|
||||||
const { text } = e.params.data;
|
const wfjt_label_id = 'workflow_job_template_labels';
|
||||||
/* If the character count of a removed label is greater than 512 AND the field is currently marked
|
// Detect when a new label is added
|
||||||
as invalid, we set it back to valid */
|
$(`#${wfjt_label_id}`).on('select2:select', (e) => {
|
||||||
if (text.length > maxCount && $scope.workflow_job_template_form.labels.$error) {
|
const { text } = e.params.data;
|
||||||
$scope.workflow_job_template_form.labels.$setValidity(`${wfjt_label_id}`, true);
|
// If the character count of an added label is greater than 512, we set `labels` field as invalid
|
||||||
$scope.workflow_job_template_labels_isValid = true;
|
if (text.length > maxCount) {
|
||||||
}
|
$scope.workflow_job_template_form.labels.$setValidity(`${wfjt_label_id}`, false);
|
||||||
});
|
$scope.workflow_job_template_labels_isValid = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Detect when a label is removed
|
||||||
|
$(`#${wfjt_label_id}`).on('select2:unselect', (e) => {
|
||||||
|
const maxCount = 512;
|
||||||
|
const { text } = e.params.data;
|
||||||
|
/* If the character count of a removed label is greater than 512 AND the field is currently marked
|
||||||
|
as invalid, we set it back to valid */
|
||||||
|
if (text.length > maxCount && $scope.workflow_job_template_form.labels.$error) {
|
||||||
|
$scope.workflow_job_template_form.labels.$setValidity(`${wfjt_label_id}`, true);
|
||||||
|
$scope.workflow_job_template_labels_isValid = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
handleLabelCount();
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -323,41 +323,45 @@ export default [
|
|||||||
$scope.invalid_survey = false;
|
$scope.invalid_survey = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
let handleLabelCount = () => {
|
||||||
* This block of code specifically handles the client-side validation of the `labels` field.
|
/**
|
||||||
* Due to it's detached nature in relation to the other job template fields, we must
|
* This block of code specifically handles the client-side validation of the `labels` field.
|
||||||
* validate this field client-side in order to avoid the edge case where a user can make a
|
* Due to it's detached nature in relation to the other job template fields, we must
|
||||||
* successful POST to the `workflow_job_templates` endpoint but however encounter a 200 error from
|
* validate this field client-side in order to avoid the edge case where a user can make a
|
||||||
* the `labels` endpoint due to a character limit.
|
* successful POST to the `workflow_job_templates` endpoint but however encounter a 200 error from
|
||||||
*
|
* the `labels` endpoint due to a character limit.
|
||||||
* We leverage two of select2's available events, `select` and `unselect`, to detect when the user
|
*
|
||||||
* has either added or removed a label. From there, we set a flag and do simple string length
|
* We leverage two of select2's available events, `select` and `unselect`, to detect when the user
|
||||||
* checks to make sure a label's chacacter count remains under 512. Otherwise, we disable the "Save" button
|
* has either added or removed a label. From there, we set a flag and do simple string length
|
||||||
* by invalidating the field and inform the user of the error.
|
* checks to make sure a label's chacacter count remains under 512. Otherwise, we disable the "Save" button
|
||||||
*/
|
* by invalidating the field and inform the user of the error.
|
||||||
|
*/
|
||||||
|
|
||||||
$scope.workflow_job_template_labels_isValid = true;
|
$scope.workflow_job_template_labels_isValid = true;
|
||||||
const maxCount = 512;
|
|
||||||
const wfjt_label_id = 'workflow_job_template_labels';
|
|
||||||
// Detect when a new label is added
|
|
||||||
$(`#${wfjt_label_id}`).on('select2:select', (e) => {
|
|
||||||
const { text } = e.params.data;
|
|
||||||
// If the character count of an added label is greater than 512, we set `labels` field as invalid
|
|
||||||
if (text.length > maxCount) {
|
|
||||||
$scope.workflow_job_template_form.labels.$setValidity(`${wfjt_label_id}`, false);
|
|
||||||
$scope.workflow_job_template_labels_isValid = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Detect when a label is removed
|
|
||||||
$(`#${wfjt_label_id}`).on('select2:unselect', (e) => {
|
|
||||||
const maxCount = 512;
|
const maxCount = 512;
|
||||||
const { text } = e.params.data;
|
const wfjt_label_id = 'workflow_job_template_labels';
|
||||||
/* If the character count of a removed label is greater than 512 AND the field is currently marked
|
// Detect when a new label is added
|
||||||
as invalid, we set it back to valid */
|
$(`#${wfjt_label_id}`).on('select2:select', (e) => {
|
||||||
if (text.length > maxCount && $scope.workflow_job_template_form.labels.$error) {
|
const { text } = e.params.data;
|
||||||
$scope.workflow_job_template_form.labels.$setValidity(`${wfjt_label_id}`, true);
|
// If the character count of an added label is greater than 512, we set `labels` field as invalid
|
||||||
$scope.workflow_job_template_labels_isValid = true;
|
if (text.length > maxCount) {
|
||||||
}
|
$scope.workflow_job_template_form.labels.$setValidity(`${wfjt_label_id}`, false);
|
||||||
});
|
$scope.workflow_job_template_labels_isValid = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Detect when a label is removed
|
||||||
|
$(`#${wfjt_label_id}`).on('select2:unselect', (e) => {
|
||||||
|
const maxCount = 512;
|
||||||
|
const { text } = e.params.data;
|
||||||
|
/* If the character count of a removed label is greater than 512 AND the field is currently marked
|
||||||
|
as invalid, we set it back to valid */
|
||||||
|
if (text.length > maxCount && $scope.workflow_job_template_form.labels.$error) {
|
||||||
|
$scope.workflow_job_template_form.labels.$setValidity(`${wfjt_label_id}`, true);
|
||||||
|
$scope.workflow_job_template_labels_isValid = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
handleLabelCount();
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user