Loading...
 
Skip to main content

History: Profile_CDF_instructions_page

Source of version: 13

Copy to clipboard
            Show case of how to use the plugin jquery to conditionally hide or display some fields in a form

First you need to validate the PluginJQ call in this page so that it can be run:
* Validate plugins: [tiki-plugins.php]
* Manage the tracker fields: [tiki-admin_tracker_fields.php?trackerId=$profileobject:cdf$]

More instructions to come. Reference info:
* https://dev.tiki.org/item5642
* http://xavi-9794-5642.show.tikiwiki.org

To be refactored still with the appropriate reference (instead of fixed numbers) for fields
{TRACKER(trackerId="$profileobject:cdf$" fields="$profileobject:cdf_id$:$profileobject:cdf_campText$:$profileobject:cdf_header$:$profileobject:cdf_usuari$:$profileobject:cdf_campRadioButton$:$profileobject:cdf_staticText$:$profileobject:cdf_multiSelectCheckboxes$:$profileobject:cdf_multiSelectList$:$profileobject:cdf_computedField$:$profileobject:cdf_campNumeric$:$profileobject:cdf_campDesplegableAmbAltres$:$profileobject:cdf_data$:$profileobject:cdf_campAreaDeText$:$profileobject:cdf_campDatepicker$:$profileobject:cdf_campDesplegable$" showtitle="y" showdesc="y" showfieldsdesc="y" showmandatory="y" showstatus="y")}Item inserted! __((Homepage|Add a new one))__{TRACKER}

{JQ()}
$("input[name=ins_$profileobject:cdf_campRadioButton$]").change(function(){
    if ($(this).val() === '0') {
        $("input[name=ins_$profileobject:cdf_campNumeric$]").parents("tr:first").hide("slow");
        $("input[name=ins_$profileobject:cdf_campNumeric$]").val("");
        $("select[name=ins_$profileobject:cdf_campDesplegableAmbAltres$]").parents("tr:first").hide("slow");
        $("select[name=ins_$profileobject:cdf_campDesplegableAmbAltres$]").val("").trigger("chosen:updated")
        $("input[name=other_ins_$profileobject:cdf_campDesplegableAmbAltres$]").val("");
        $("select[name=ins_$profileobject:cdf_data$Year]").parents("tr:first").hide("slow");
        $("select", ".tracker_field$profileobject:cdf_data$").val("").trigger("chosen:updated");
        $("textarea[name=ins_$profileobject:cdf_campAreaDeText$]").parents("tr:first").hide("slow");
        $("textarea[name=ins_$profileobject:cdf_campAreaDeText$]").val("");
        $("input[name=ins_$profileobject:cdf_campDatepicker$]").parents("tr:first").hide("slow");
        $("input[name=ins_$profileobject:cdf_campDatepicker$]").next().val("");
        $("input[name=ins_$profileobject:cdf_campRadioButton$]").parents("tr:first")
            .css('font-weight', 'bold')
            .css('background-color', 'cyan')
            .focus(function() {
                $(this)
                    .css('font-weight', '')
                    .css('background-color', '');
            });
        $(".wikiplugin_tracker:eq(1) tr").slice(2, 6).css({backgroundColor:"lightcyan", fontStyle:"italic", color:"grey"});
        $("label[for=ins_$profileobject:cdf_staticText$]").parents("tr:first").show("slow");
        $("input[name=ins_$profileobject:cdf_multiSelectCheckboxes$_old]").parents("tr:first").show("slow");
        $("label[for=ins_$profileobject:cdf_multiSelectList$]").parents("tr:first").show("slow");
        $("label[for=ins_$profileobject:cdf_computedField$]").parents("tr:first").show("slow");
    } else if ($(this).val() === '1') {
        $("input[name=ins_$profileobject:cdf_campNumeric$]").parents("tr:first").show("slow");
        $("select[name=ins_$profileobject:cdf_campDesplegableAmbAltres$]").parents("tr:first").show("slow");
        $("select[name=ins_$profileobject:cdf_data$Year]").parents("tr:first").show("slow");
        $("textarea[name=ins_$profileobject:cdf_campAreaDeText$]").parents("tr:first").show("slow");
        $("input[name=ins_$profileobject:cdf_campDatepicker$]").parents("tr:first").show("slow");
        $("input[name=ins_$profileobject:cdf_campRadioButton$]").parents("tr:first")
            .css('font-weight', 'bold')
            .css('background-color', 'yellow')
            .focus(function() {
                $(this)
                    .css('font-weight', '')
                    .css('background-color', '');
            });
        // This a comment
        $(".wikiplugin_tracker:eq(1) tr").slice(6, 11).css({backgroundColor:"lightyellow", fontStyle:"italic", color:"grey"}); /* this is another comment */
        $("label[for=ins_$profileobject:cdf_staticText$]").parents("tr:first").hide("slow");
        $("input[name=ins_$profileobject:cdf_multiSelectCheckboxes$_old]").parents("tr:first").hide("slow");
        $("input[name='ins_$profileobject:cdf_multiSelectCheckboxes$[]']").prop("checked", false)
        $("label[for=ins_$profileobject:cdf_multiSelectList$]").parents("tr:first").hide("slow");
        $("select[name='ins_$profileobject:cdf_multiSelectList$[]'] option:selected").prop("selected", false)
        $("select[name='ins_$profileobject:cdf_multiSelectList$[]']").trigger("chosen:updated")
        $("label[for=ins_$profileobject:cdf_computedField$]").parents("tr:first").hide("slow");
    } else {
        $("input[name=ins_$profileobject:cdf_campNumeric$]").parents("tr:first").hide("slow");
        $("input[name=ins_$profileobject:cdf_campNumeric$]").val("");
        $("select[name=ins_$profileobject:cdf_campDesplegableAmbAltres$]").parents("tr:first").hide("slow");
        $("select[name=ins_$profileobject:cdf_campDesplegableAmbAltres$]").val("").trigger("chosen:updated");
        $("input[name=other_ins_$profileobject:cdf_campDesplegableAmbAltres$]").val("").trigger("chosen:updated");
        $("select[name=ins_$profileobject:cdf_data$Year]").parents("tr:first").hide("slow");
        $("select", ".tracker_field$profileobject:cdf_data$").val("").trigger("chosen:updated")
        $("textarea[name=ins_$profileobject:cdf_campAreaDeText$]").parents("tr:first").hide("slow");
        $("textarea[name=ins_$profileobject:cdf_campAreaDeText$]").val("");
        $("label[for=ins_$profileobject:cdf_campDatepicker$]").parents("tr:first").hide("slow");
        $("#" + $("input[name=ins_$profileobject:cdf_campDatepicker$]").attr("id") + "_dptxt").val("");
        $("label[for=ins_$profileobject:cdf_staticText$]").parents("tr:first").hide("slow");
        $("input[name=ins_$profileobject:cdf_staticText$]").val("");
        $("input[name=ins_$profileobject:cdf_multiSelectCheckboxes$_old]").parents("tr:first").hide("slow");
        $("input[name='ins_$profileobject:cdf_multiSelectCheckboxes$[]']").prop("checked", false)
        $("label[for=ins_$profileobject:cdf_multiSelectList$]").parents("tr:first").hide("slow");
        $("select[name='ins_$profileobject:cdf_multiSelectList$[]'] option:selected").prop("selected", false)
        $("select[name='ins_$profileobject:cdf_multiSelectList$[]']").trigger("chosen:updated")
        $("label[for=ins_$profileobject:cdf_computedField$]").parents("tr:first").hide("slow");
        $("label[for=ins_$profileobject:cdf_computedField$]").val("");
        $("input[name=ins_$profileobject:cdf_campRadioButton$]").parents("tr:first")
            .css('font-weight', 'normal')
            .css('background-color', 'lightgrey')
            .focus(function() {
                $(this)
                    .css('font-weight', '')
                    .css('background-color', '');
            });
    }
});
$("input[name=ins_$profileobject:cdf_campNumeric$]").parents("tr:first").hide();
$("select[name=ins_$profileobject:cdf_campDesplegableAmbAltres$]").parents("tr:first").hide();
$("select[name=ins_$profileobject:cdf_data$Year]").parents("tr:first").hide();
$("textarea[name=ins_$profileobject:cdf_campAreaDeText$]").parents("tr:first").hide();
$("input[name=ins_$profileobject:cdf_campDatepicker$]").parents("tr:first").hide();
$("label[for=ins_$profileobject:cdf_staticText$]").parents("tr:first").hide();
$("input[name=ins_$profileobject:cdf_multiSelectCheckboxes$_old]").parents("tr:first").hide();
$("label[for=ins_$profileobject:cdf_multiSelectList$]").parents("tr:first").hide();
$("label[for=ins_$profileobject:cdf_computedField$]").parents("tr:first").hide();
{JQ}

        

History

Information Version
Fri 24 of Jul, 2015 15:10 GMT-0000 Xavier de Pedro edited according to jonnyb's tips so that the required fields are shown when editing a previously saved item (thanks!) 18
Sun 26 of Apr, 2015 12:43 GMT-0000 Xavier de Pedro fixed ref to page name 17
Sun 26 of Apr, 2015 12:29 GMT-0000 Xavier de Pedro typo 16
Sun 26 of Apr, 2015 12:29 GMT-0000 Xavier de Pedro hide ref info as a tiki comment, and made link to page to add new item through the reference to the page defined in the profile 15
Sun 26 of Apr, 2015 12:11 GMT-0000 Xavier de Pedro added comment 14
Sun 26 of Apr, 2015 12:08 GMT-0000 Xavier de Pedro fixed refs to tracker1 (0 is first, and header breaks the table 0 into another table (1) in that wiki page, so refer to 1 as hardcoded value. Try jq comments 13
Sun 26 of Apr, 2015 11:52 GMT-0000 Xavier de Pedro removed old code from Export. added links at the top 12
Sun 26 of Apr, 2015 11:40 GMT-0000 Xavier de Pedro changed colors a bit and re-ordered code position for consistency 11
Sun 26 of Apr, 2015 11:31 GMT-0000 Xavier de Pedro made reference to tracker id dynamic, and fix positions of slice ranges for field bg colors 10
Sun 26 of Apr, 2015 11:22 GMT-0000 Xavier de Pedro tweaked 9
Sun 26 of Apr, 2015 11:09 GMT-0000 Xavier de Pedro hide code 8
Sun 26 of Apr, 2015 11:06 GMT-0000 Xavier de Pedro fixed a few more params 7
Sat 25 of Apr, 2015 12:25 GMT-0000 Xavier de Pedro fixed profileobject:cdf_campRadioButton 6
Sat 25 of Apr, 2015 12:21 GMT-0000 Xavier de Pedro a bit more fixed 5
Fri 24 of Apr, 2015 21:15 GMT-0000 Xavier de Pedro tweaked some of them 4
Fri 24 of Apr, 2015 16:03 GMT-0000 Xavier de Pedro added raw material 3
Fri 24 of Apr, 2015 15:22 GMT-0000 Xavier de Pedro more info 2
Fri 24 of Apr, 2015 15:20 GMT-0000 Xavier de Pedro ini 1