<commit_before>;

function disable_field_based_on_value(field, value) {
    if (field.val() == value) {
        field.attr('disabled', 'disabled')
    }
}

function hide_between_value_fields() {
    var min_value_field = $('#id_min_value');
    var max_value_field = $('#id_max_value');
    min_value_field.hide();
    min_value_field.attr('disabled', 'disabled');
    max_value_field.hide();
    max_value_field.attr('disabled', 'disabled');
}

function show_between_value_fields(){
    var min_value_field = $('#id_min_value');
    var max_value_field = $('#id_max_value');
    var value_field = $('#id_value');
    min_value_field.show();
    min_value_field.attr('disabled', false);
    max_value_field.show();
    max_value_field.attr('disabled', false);
    value_field.hide();
    value_field.attr('disabled', 'disabled');
}

function show_or_hide_attribute_fields(attribute_value){
    var value_field = $('#id_value');

    hide_between_value_fields();

    if ($('#id_condition').val().toUpperCase() != 'BETWEEN'){
        hide_between_value_fields()
        if(attribute_value == 'value'){
            value_field.show();
            value_field.attr('disabled', false);
        }

    }
    if ($('#id_condition').val().toUpperCase() == 'BETWEEN'){
        show_between_value_fields()
    }
}

function show_or_hide_next_question(action_value) {
    show_next_question = ['SKIP_TO', 'ASK_SUBQUESTION', 'BACK_TO'];
    var next_question_field = $('#id_next_question');
    if (show_next_question.indexOf(action_value) != -1) {
        next_question_field.show();
        next_question_field.attr('disabled', false)
    }
    else {
        $('#add_subquestion').hide();
        next_question_field.hide();
        next_question_field.attr('disabled', 'disabled')
    }
    next_question_field.hide();
    $(' .chzn-select').trigger("liszt:updated");
}

function append_to_next_question_dropdown(data) {
    counter=0;
    $.each(data, function () {
        $('#id_next_question').append("<option value=" + data[counter]['id'] + ">" + data[counter]['identifier'] + " -- "+ data[counter]['text'] + "</option>");
        counter++;
    });
     $(' .chzn-select').trigger("liszt:updated");
}

function append_to_drop_down_options(url)
{
    $.get( url, function( data ) {
        append_to_next_question_dropdown(data);
    });
}

function replace_next_question_with_right_data(questions_url) {
    if(questions_url != ""){
    $('#id_next_question').find('option')
        .remove()
        .end()
    }
    append_to_drop_down_options(questions_url)
    $(' .chzn-select').trigger("liszt:updated");
}

function append_attribute_option(key, value) {
    //$('#id_attribute').append("<option value=" + key + ">" + value + "</option>");
}

function clear_attribute_dropdown_and_append_right_option(condition_selected){
    condition_selected = condition_selected.toUpperCase()
    if(condition_selected == "BETWEEN"){
        $("#id_value").hide();
        show_between_value_fields();
    }
    else {
        $("#id_value").show();
        hide_between_value_fields();
    }
}

function fill_questions_or_subquestions_in_next_question_field(action_value){
    var show_questions = ['SKIP_TO'];
    var show_sub_questions = ['ASK_SUBQUESTION'];
    var show_back_to_questions = ['BACK_TO'];
    var question_id = $('#id_question').val();
    var batch_id = $('#id_batch').val()
    var questions_url = "";
    if(show_questions.indexOf(action_value) != -1)
    {
        questions_url = '/batches/'+ batch_id+'/questions/' + question_id +'/questions_json/'
        $('#add_subquestion').hide();
    }
    else if (show_sub_questions.indexOf(action_value) != -1)
    {
        questions_url = '/questions/' + question_id +'/sub_questions_json/'
        $('#add_subquestion').show();
    }
    else if(show_back_to_questions.indexOf(action_value) != -1)
    {
        questions_url = '/questions/' + question_id +'/prev_questions_json/'
        $('#add_subquestion').hide();
    }
    replace_next_question_with_right_data(questions_url);
}

function isHTML(str) {
    var a = document.createElement('div');
    a.innerHTML = str;
    for (var c = a.childNodes, i = c.length; i--; ) {
        if (c[i].nodeType == 1) return true;
    }
    return false;
}

function clear_all_errors(){
    $('#id_value').next().text('');
}

jQuery(function($){
    var condition = $('#id_condition');
    var condition_value = 'EQUALS_OPTION';
    var attribute = $('#id_attribute');
    var attribute_value = 'option';
    var action_value = $('#id_action');
    disable_field_based_on_value(condition, condition_value);
    disable_field_based_on_value(attribute, attribute_value);
    show_or_hide_attribute_fields(attribute.val());
    show_or_hide_next_question(action_value.val());
    $('#add_subquestion').hide();
    condition.on('change', function(){
        show_or_hide_attribute_fields(attribute.val());
    });<commit_msg>fixed logic.js issue for skip & sub question next quest field toggling<commit_after>;

function disable_field_based_on_value(field, value) {
    if (field.val() == value) {
        field.attr('disabled', 'disabled')
    }
}

function hide_between_value_fields() {
    var min_value_field = $('#id_min_value');
    var max_value_field = $('#id_max_value');
    min_value_field.hide();
    min_value_field.attr('disabled', 'disabled');
    max_value_field.hide();
    max_value_field.attr('disabled', 'disabled');
}

function show_between_value_fields(){
    var min_value_field = $('#id_min_value');
    var max_value_field = $('#id_max_value');
    var value_field = $('#id_value');
    min_value_field.show();
    min_value_field.attr('disabled', false);
    max_value_field.show();
    max_value_field.attr('disabled', false);
    value_field.hide();
    value_field.attr('disabled', 'disabled');
}

function show_or_hide_attribute_fields(attribute_value){
    var value_field = $('#id_value');

    hide_between_value_fields();

    if ($('#id_condition').val().toUpperCase() != 'BETWEEN'){
        hide_between_value_fields()
        if(attribute_value == 'value'){
            value_field.show();
            value_field.attr('disabled', false);
        }

    }
    if ($('#id_condition').val().toUpperCase() == 'BETWEEN'){
        show_between_value_fields()
    }
}

function show_or_hide_next_question(action_value) {
    show_next_question = ['SKIP_TO', 'ASK_SUBQUESTION', 'BACK_TO'];
    var next_question_field = $('#id_next_question');
    if (show_next_question.indexOf(action_value) != -1) {
        next_question_field.show();
        next_question_field.attr('disabled', false)
    }
    else {
        $('#add_subquestion').hide();
        next_question_field.hide();
        next_question_field.attr('disabled', 'disabled')
    }
    $(' .chzn-select').trigger("liszt:updated");
}

function append_to_next_question_dropdown(data) {
    counter=0;
    $.each(data, function () {
        $('#id_next_question').append("<option value=" + data[counter]['id'] + ">" + data[counter]['identifier'] + " -- "+ data[counter]['text'] + "</option>");
        counter++;
    });
     $(' .chzn-select').trigger("liszt:updated");
}

function append_to_drop_down_options(url)
{
    $.get( url, function( data ) {
        append_to_next_question_dropdown(data);
    });
}

function replace_next_question_with_right_data(questions_url) {
    if(questions_url != ""){
    $('#id_next_question').find('option')
        .remove()
        .end()
    }
    append_to_drop_down_options(questions_url)
    $(' .chzn-select').trigger("liszt:updated");
}

function append_attribute_option(key, value) {
    //$('#id_attribute').append("<option value=" + key + ">" + value + "</option>");
}

function clear_attribute_dropdown_and_append_right_option(condition_selected){
    condition_selected = condition_selected.toUpperCase()
    if(condition_selected == "BETWEEN"){
        $("#id_value").hide();
        show_between_value_fields();
    }
    else {
        $("#id_value").show();
        hide_between_value_fields();
    }
}

function fill_questions_or_subquestions_in_next_question_field(action_value){
    var show_questions = ['SKIP_TO'];
    var show_sub_questions = ['ASK_SUBQUESTION'];
    var show_back_to_questions = ['BACK_TO'];
    var question_id = $('#id_question').val();
    var batch_id = $('#id_batch').val();
    var questions_url = "";
    if(show_questions.indexOf(action_value) != -1)
    {
        questions_url = '/batches/'+ batch_id+'/questions/' + question_id +'/questions_json/'
        $('#add_subquestion').hide();
    }
    else if (show_sub_questions.indexOf(action_value) != -1)
    {
        questions_url = '/questions/' + question_id +'/sub_questions_json/'
        $('#add_subquestion').show();
    }
    else if(show_back_to_questions.indexOf(action_value) != -1)
    {
        questions_url = '/questions/' + question_id +'/prev_questions_json/'
        $('#add_subquestion').hide();
    }
    if(questions_url)
        replace_next_question_with_right_data(questions_url);
}

function isHTML(str) {
    var a = document.createElement('div');
    a.innerHTML = str;
    for (var c = a.childNodes, i = c.length; i--; ) {
        if (c[i].nodeType == 1) return true;
    }
    return false;
}

function clear_all_errors(){
    $('#id_value').next().text('');
}

jQuery(function($){
    var condition = $('#id_condition');
    var condition_value = 'EQUALS_OPTION';
    var attribute = $('#id_attribute');
    var attribute_value = 'option';
    var action_value = $('#id_action');
    disable_field_based_on_value(condition, condition_value);
    disable_field_based_on_value(attribute, attribute_value);
    show_or_hide_attribute_fields(attribute.val());
    show_or_hide_next_question(action_value.val());
    $('#add_subquestion').hide();
    condition.on('change', function(){
        show_or_hide_attribute_fields(attribute.val());
    });
{'fraction_non_alphanumeric': 0.16346930533117932, 'fraction_numerical': 0.0012116316639741518, 'mean_word_length': 3.8601570166830226, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6406307', 'n_tokens_mistral': 3198, 'n_tokens_neox': 3161, 'n_words': 462}