1

I have sharepoint on-premises 2013, and i have add the following javascript inside my New list form.

$(document).ready(function () {

    function init() {

    $('input[id^="SupplierCost_"]').change(function(){
    calculateresults();
         });
    $(document).on('change','input',function(e){

    $("Div:contains(Calculation Completed)").css("color", "#008CD2");
    $("Div:contains(Can not Calculate)").css("color", "red");  

});

    }
function initTaggingControl() {
    RTE.CanvasEvents.registerListener(RTE.CanvasEvents.editableRegionChangedEvent, Function.createDelegate(null, onCustomTextChanged));

  }

function onCustomTextChanged(sender, args){
     var ll = $(args.editableRegion).parents().length;
   if(args.editableRegion.innerText.length > 0){ 

   for(var j=0;j<ll;j++)
   {
     var a =  $(args.editableRegion).parents()[j].FieldName ;

    if (a === "Name" || a === "Cost")
    {
         calculateresults();
       }

       }
   }    
  }

  function calculateresults(){

    if(data.d.results.length>0){
    SPUtility.GetSPFieldByInternalName('CalculationResult').SetValue("Calculation Completed");
    }   
    else
    {
    SPUtility.GetSPFieldByInternalName('CalculationResult').SetValue("Can not calculate"); 
    }
  }  
    ExecuteOrDelayUntilScriptLoaded(initTaggingControl, 'ScriptForWebTaggingUI.js');
    ExecuteOrDelayUntilScriptLoaded(init, "sp.js");
     }      
    });

So inside the above script (which i added to the list New form) i am doing the following:-

  1. i am populating a list column named "Calculation Result ", with any of these 2 messages:-

    • Calculation Completed
    • Can not Calculate
  2. also i define this function, to color the text either to red or blue, depending on the Div text:-

$(document).on('change','input',function(e){

        $("Div:contains(Calculation Completed)").css("color", "#008CD2");
        $("Div:contains(Can not Calculate)").css("color", "red");  

    });

but the problem i am facing that the color (red or blue) will be applied to all the input fields inside the form, and not only with the one which satisfy the Div:contains rule, here is a screen shot from the form, where 2 fields were colored to RED:-

enter image description here

so can anyone advice on this please?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.