Rules with Readonly Checkboxes

Forums Dynamic Forms for SharePoint Rules with Readonly Checkboxes

Viewing 7 reply threads
  • Author
    Posts
    • #8255
      DCH
      Participant

      Alexander,

      I wrote a rule that made a checkbox field readonly. I assumed it would leave the checkbox selections visible and just disable them so they could not be checked or unchecked. But instead the whole field disappeared. Is that how it is supposed to work?

      And a related question, is it possible through DFFS rules to make specific checkbox choices readonly, but leave others available, within the same column?

      Thanks!

    • #8265
      Alexander Bautz
      Keymaster

      Using a readonly representation of a checkbox field makes sense, I have therefore added this to the upcoming release.

      Your other request will however not be added as default functionality, but you can add this custom code to achieve it.

      Add this to the “Run these functions / trigger these rules” in the rule:

      readonlyCheckbox

      Then add this to the Custom JS textarea in the “Field table, Custom JS and CSS” tab:

      function readonlyCheckbox(){
      	spjs.$("#dffs_Color").find("input:checkbox").each(function(i,c){
      		if(spjs.$(c).next().text() === "Blue"){
      			spjs.$(c).prop("disabled",true);
      		}
      	});
      }

      Change “Color” to your field internal name and “Blue” to the option you want to set as readonly.

      Alexander

    • #24485
      Andreas Blüher
      Participant

      Hello Alexander,

      I found this thread because I stumbled up on the same issue. Although using a quiet new version checkboxes are still being removed instead of being disabled.

      Is it still required to use the script or should it be included in the latest release?

      Kind Regards,
      Andreas

    • #24490
      Alexander Bautz
      Keymaster

      Hi,
      This was added back in 2015 – can you show me some screenshots so I can see how it looks in your form?

      PS: If it is in DispForm, you will have to use a custom script like this:

      function showCheckboxesInDispForm(fin) {
          jQuery.ajax({
              "url": _spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/getbyid('" + _spPageContextInfo.pageListId + "')/fields/getByInternalNameOrTitle('" + fin + "')",
              "method": "GET",
              "headers": { "Accept": "application/json; odata=verbose" },
              "success": function (data) {
                  var arr = data.d.Choices.results, b = [], currentChoicesArr = getFieldValue(fin).split("; ");
                  jQuery.each(arr, function (i, c) {
                      var checked = jQuery.inArray(c, currentChoicesArr) > -1;
                      b.push("<span class='ms-RadioText' title='" + c + "'><input type='checkbox'" + (checked ? " checked='checked'" : "") + " disabled><label>" + c + "</label></span>");
                  });
                  jQuery("#dffs_" + fin + " td.ms-formbody").html(b.join("<br>"));
              },
              "error": function (data) {
                  console.log("Error getting field choices:");
                  console.log(data);
              }
          });
      }
      showCheckboxesInDispForm("ToDo"); // Call with the FieldInternalName of the field

      Alexander

    • #24515
      Andreas Blüher
      Participant

      I wasn’t honest about the “almost latest version”. I’m using

      DFFS frontend: 4.4.3.47
      DFFS frontend CSS: 4.44 /
      Autocomplete: 1.6.22
      Cascading dropdowns: 3.7.22
      jQuery: 1.12.4
      Lookup: 1.1.11
      Resource management: not loaded
      SPJS-Utility: 1.323
      vLookup: 2.2.122

      So as you can see the checkbox is visible in my EditForm and after setting the boolean field to be readonly the checkbox is set to display:none;

      I’m sorry if I’m missing something obvious here.

      Cheers Andreas

    • #24525
      Alexander Bautz
      Keymaster

      The problem is that the readonly checkbox icon is the same color as you have chosen as form background color. You must override the default color by adding this to your custom css:

      .dffs-readonly-inner *{
          color:#000000!important;
      }

      Alexander

    • #24533
      Andreas Blüher
      Participant

      Thank you for your help, I feel stupid but it was very unfortunate that my customer did choose the same color for their background :O

    • #24535
      Alexander Bautz
      Keymaster

      No problem, I’m glad we figured it out.

      Alexander

Viewing 7 reply threads
  • You must be logged in to reply to this topic.