Render webhooks form url errors using data-error-text attribute [SCI-9743] (#6869)

This commit is contained in:
wandji 2024-01-03 19:08:33 +01:00 committed by GitHub
parent dd312062d3
commit 9ade9e890f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 3 deletions

View file

@ -24,7 +24,13 @@
});
}
$('.activity-filters-list').on('ajax:error', '.webhook-form', function(e, data) {
$(this).renderFormErrors('webhook', data.responseJSON.errors);
const { errors } = data.responseJSON;
// display url errors with data-error-text attribute
if (errors.url) {
$(this).find('.url-input-container').addClass('error').attr('data-error-text', `${errors.url.join(', ')}`);
delete errors.url;
}
$(this).renderFormErrors('webhook', errors);
});
$('.activity-filters-list').on('click', '.create-webhook', function() {
@ -33,6 +39,11 @@
filterElement.find('.create-webhook-container').removeClass('hidden');
});
// clear url form errors
$('.activity-filters-list').on('click', '.cancel-action, .save-webhook', () => {
$('.url-input-container').removeClass('error').attr('data-error-text', '');
});
$('.activity-filters-list').on('click', '.create-webhook-container .cancel-action', function(e) {
let webhookContainer = $(this).closest('.create-webhook-container');
e.preventDefault();

View file

@ -111,7 +111,7 @@
</div>
</div>
<div class="edit-webhook-container hidden">
<%= form_with model: webhook, url: users_settings_webhook_path(webhook, filter_id: filter.id, sort: @current_sort), class: 'webhook-form', method: :patch do |f| %>
<%= form_with model: webhook, url: users_settings_webhook_path(webhook, filter_id: filter.id, sort: @current_sort), class: 'webhook-form', method: :patch, data: { remote: true } do |f| %>
<%= render partial: 'webhook_form', locals: {f: f} %>
<% end %>
</div>

View file

@ -220,7 +220,7 @@ en:
configuration:
disabled: 'Webhooks are disabled'
url:
not_valid: 'Not valid URL'
not_valid: 'not valid URL'
result_text:
attributes:
text: