Skip to content

Commit

Permalink
dynamic form with advance options
Browse files Browse the repository at this point in the history
to be more user-friendly, this setting allows hidding advance options for advance users
  • Loading branch information
hsnfirooz committed Dec 5, 2024
1 parent a9fcb67 commit a688c09
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
42 changes: 40 additions & 2 deletions bin/deploy-data/ood/form.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
/**
* Decode the audio_path to replace '%20' with space
*/

// File path in OOD has a prefix
const OOD_PREFIX_PATH = "/pun/sys/dashboard/files/fs/";

function decode_audio_path() {
let audio_path = $("#batch_connect_session_context_audio_path");
let selectedFiles = [];

// Find all rows with the 'selected' class
$("#batch_connect_session_context_audio_path_path_selector_table tr.selected").each(function() {
// Extract the file path from the data attribute
let filePath = $(this).data("api-url");
if (filePath) {
let absolutePath = filePath.replace(OOD_PREFIX_PATH, ''); // Remove the prefix from the path
selectedFiles.push(decodeURIComponent(absolutePath));
}
});

// Join paths with a separator, e.g., comma
$("#batch_connect_session_context_audio_path").val(selectedFiles.join('; '));

audio_path.val(decodeURIComponent(audio_path.val()))
}


Expand Down Expand Up @@ -47,6 +63,18 @@ function validate_AudioPath(event) {
}


function toggle_visibilty_of_form_group(form_id, show) {
let form_element = $(form_id);
let parent = form_element.parent();
console.log("Show value:", show);
if(show == true) {
parent.show();
} else {
parent.hide();
}
}


/**
* Sets the event handler for file selector button.
* Triggering the handler based on the field change doesn't work
Expand All @@ -67,6 +95,13 @@ function add_event_handlers() {

let submit_button = $("input[type='submit'][name='commit']");
submit_button.click(validate_AudioPath);

let advance_settings = $("#batch_connect_session_context_advance_options");
advance_settings.change(function() {
toggle_visibilty_of_form_group(
"#batch_connect_session_context_model_selector",
advance_settings.is(':checked'))
});
}


Expand All @@ -75,4 +110,7 @@ function add_event_handlers() {
*/
$(document).ready(function () {
add_event_handlers();

// Hide the advance settings at the beggining
toggle_visibilty_of_form_group("#batch_connect_session_context_model_selector", 'false')
});
11 changes: 11 additions & 0 deletions bin/deploy-data/ood/form.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ form:
- email_field
- send_attachments
- language_field
- advance_options
- model_selector

attributes:
Expand Down Expand Up @@ -51,6 +52,16 @@ attributes:
Select this option to recieve the transcripted files to your email.
advance_options:
label: "Advance Settings"
display: false
widget: check_box
checked_value: true
unchecked_value: false
help: |
Show advance settings.
model_selector:
label: Model
widget: select
Expand Down

0 comments on commit a688c09

Please sign in to comment.