0

On dropdown change event i am making a column mandatory. if you see the below picenter image description here for the first time when TypeofRequest="508web" what format should be return as becomes mandatory. The below code works fine for the first time when i change the dropdown. Once i change the value and come back it is adding 2 stars to the nobr text (refer screen shot below). enter image description here

how can we over come this

Function for the same

function MandateColumn(ColNames, mandatory)
{for(var i=0;i<ColNames.length;i++)
    {       
    if(mandatory=="True"){ var controlvalidate= $("[id^='"+ColNames[i]+"']").prev('td').text();
       var spanTag ="<span class=\"ms-formvalidation\"> *</span>";
       var newHtml1 = controlvalidate;
           newHtml =newHtml1 + spanTag;               
           $("nobr").filter(function()
              {return $(this).text() === controlvalidate;}).html(newHtml);}else{ }}}

Calling the above function (

var BPHCMandateCols= ['FormatShouldReturnas'];
                      MandateColumn(BPHCMandateCols,"True")
  • Did you try removing the "*" from var spanTag ="<span class=\"ms-formvalidation\"> *</span>"; ? – Sohail Shaikh Oct 16 '18 at 17:16
  • Yes,If i Remove the * for the first time it self it will not add it. – santosh kondapalli Oct 16 '18 at 17:53
  • So why do you purposely add * ?,however ms-formvalidation itself renders the * – Sohail Shaikh Oct 16 '18 at 18:31
0

I was able to achieve this by removing the span tag.

$("[id^='"+ColNames[i]+"']").prev('td').find('.ms-formvalidation').remove();
function MandateColumn(ColNames, mandatory)
{   
    for(var i=0;i<ColNames.length;i++)
    {

    if(mandatory=="True")
    {   
     $("[id^='"+ColNames[i]+"']").prev('td').find('.ms-formvalidation').remove();
       var controlvalidate= $("[id^='"+ColNames[i]+"']").prev('td').text();
       var newHtml1 = controlvalidate;
       $("nobr").filter(function()
              {return $(this).text() === controlvalidate;}).html(newHtml1);
       var spanTag ="<span class=\"ms-formvalidation\">*</span>";

           newHtml =newHtml1 + spanTag;               
           $("nobr").filter(function()
              {return $(this).text() === controlvalidate;}).html(newHtml);


    }
      else{ 


      }
    }
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.