From 51fa6ccf4b0f6f8b24a885e1086acd5e8cab6f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mauro=20Ferr=C3=A3o?= Date: Mon, 23 Dec 2024 13:51:55 +0000 Subject: [PATCH] Dataset form: Validation broken for uri field (#2835) relates to xibosignageltd/xibo-private#882 --- ui/src/core/xibo-cms.js | 2 +- views/dataset-form-add.twig | 2 +- views/dataset-form-edit.twig | 2 +- views/dataset-page.twig | 20 ++++++++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ui/src/core/xibo-cms.js b/ui/src/core/xibo-cms.js index 6f3d81278f..0a65856cd7 100644 --- a/ui/src/core/xibo-cms.js +++ b/ui/src/core/xibo-cms.js @@ -164,7 +164,7 @@ window.XiboInitialise = function(scope, options) { }); // Form validation - $(scope + ' .XiboForm').each((_idx, form) => { + $(scope + ' .XiboForm:not(.custom-validation)').each((_idx, form) => { const $form = $(form); forms.validateForm( $form, // form diff --git a/views/dataset-form-add.twig b/views/dataset-form-add.twig index 2ae534d19c..3c4e76eafb 100644 --- a/views/dataset-form-add.twig +++ b/views/dataset-form-add.twig @@ -45,7 +45,7 @@ -
+
diff --git a/views/dataset-form-edit.twig b/views/dataset-form-edit.twig index 9efc893586..c6db3dd624 100644 --- a/views/dataset-form-edit.twig +++ b/views/dataset-form-edit.twig @@ -45,7 +45,7 @@ - +
diff --git a/views/dataset-page.twig b/views/dataset-page.twig index 6f0fef51fe..969177d94a 100644 --- a/views/dataset-page.twig +++ b/views/dataset-page.twig @@ -353,6 +353,26 @@ $(dialog).find('#sourceId').on('change', function() { onSourceFieldChanged(dialog); }); + + // Validate form manually because + // uri field depends on isRemote being checked + if (forms != undefined) { + const $form = $(dialog).find('form'); + forms.validateForm( + $form, // form + $form.parent(), // container + { + submitHandler: XiboFormSubmit, + rules: { + uri: { + required: function(element) { + return $form.find('#isRemote').is(':checked') + }, + }, + }, + }, + ); + } } function onIsRealTimeFieldChanged(dialog) {