From d118ecdc537b9c5dfb6c4ec7af3841ed9e5a3972 Mon Sep 17 00:00:00 2001 From: maurofmferrao Date: Thu, 19 Dec 2024 11:16:56 +0000 Subject: [PATCH] Dataset form: Validation broken for uri field 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 899ec941bc..df7cbbdbcc 100644 --- a/ui/src/core/xibo-cms.js +++ b/ui/src/core/xibo-cms.js @@ -156,7 +156,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) {