You are viewing limited content. For full access, please sign in.

Question

Question

How to remove a character in a Table Field

asked on February 16, 2016

I have a form that accepts barcode data.  One field called, Work Order#, should begin with Wxxxxxx.  However, the data from the barcode prefixes it with %2.  I am looking to see if I can tell forms to drop/remove the %2 from the field automatically.

See screen shot below.

0 0

Replies

replied on February 16, 2016

Hi Jason,

You should be able to add a css class called "barcode" to the Work Order# field then use this custom Javascript:

$(document).ready(function() {
   $(".barcode input").on("blur", function(){
       $(this).val($(this).val().replace('%2', ''));
   });
});

Then when you move the cursor out of the work order input it will remove "%2" if it's found within the input.

Hope this helps!

Dan

0 0
replied on February 16, 2016

Thanks Dan!  It worked marvelously.  You are SOO awesome.  Thank you for saving me so much time!!!wink

0 0
replied on February 16, 2016

Is the code the same for a suffix removal?

 

I tried to alter the code to reflect a CSS Class on a different field wherein I am trying  to remove the trailing % this time.  However, unlike your code, this does not remove the % data from the end of the data in that field. 

I modified your code to try the same test on this particular field configured with CSS as SEQ as well with no positive results.

$(document).ready(function() {
   $(".SEQ input").on("blur", function(){
       $(this).val($(this).val().replace('%', ''));
     });
});

replied on February 16, 2016

That should be right, although if you need to use it again on the same form you'll only need the first and last line once (if that makes sense!) as they basically just tell the script to run when the document first loads. So your finished script would be:

$(document).ready(function() {

     $(".barcode input").on("blur", function(){
       $(this).val($(this).val().replace('%2', ''));
     });
   $(".SEQ input").on("blur", function(){
       $(this).val($(this).val().replace('%', ''));
     });
});

If this doesn't sort it let me know!

Cheers, Dan

0 0
replied on October 5, 2016

Good morning.  The page has changed so now the new rows that require the script to run are added by using the ADD function of forms.  The result is that the script only runs on the first line/row intially created.  Any subsequent lines/rows that are created by using the Add feature of Forms do not kick the script to run.

What changes in the script can be made to enable to script to run any time a new row is added?

 

Thanks

0 0
replied on October 5, 2016

Hi Jason,

Providing the above is the only javascript you have on the form you should just be able to delete it and replace it with the below:

$(document).ready(function() {

      removeChars();

     $(".cf-table-add-row").on("click", function(){

          removeChars();

     });
});

function removeChars() {

     $(".barcode input").on("blur", function(){
       $(this).val($(this).val().replace('%2', ''));
     });
   $(".SEQ input").on("blur", function(){
       $(this).val($(this).val().replace('%', ''));
     });

}

To get my excuses in early... I haven't had chance to test this so let me know if it doesn't work wink

Cheers, Dan

0 0
replied on October 5, 2016

Hello Dan.  There is other javascript on the form.  Any other suggestions?

 

jQuery(document).ready(function($){
    $(".EMPID input").focus();
});


$(document).ready(function() {

      removeChars();

     $(".cf-table-add-row").on("click", function(){

          removeChars();

     });
});

function removeChars() {

     $(".barcode input").on("blur", function(){
       $(this).val($(this).val().replace('%2', ''));
     });
   $(".SEQ input").on("blur", function(){
       $(this).val($(this).val().replace('%', ''));
     });

}

$(document).ready(function() {
  var $submit = $('.Submit');
 
  $submit.hide();
  $('.work').on('blur', 'input', runTotal);
  $('.tindh').on('blur', 'input', runTotal);
  function parseNumber(n) { 
        var f = parseFloat(n); //Convert to float number. 
        return isNaN(f) ? 0 : f; //treat invalid input as 0; 
    }
  function runTotal()
  {
    var sum = 0;
    var workhours = parseNumber($('.work input').val());
    var indhours = parseNumber($('.diff input').val());
    var machours = parseNumber($('.machine input').val());
    sum = parseNumber(workhours) - parseNumber(machours);
    
    if((workhours > 0) && (workhours <= machours) && (indhours == 0))
    {
      alert("Work <= Machine and Indirect is zero");
      $submit.show();
    }    
    else if((workhours > machours) && (indhours == sum))
    {
      alert("Work is greater Machine and Indirect is the difference.")
      $submit.show();
    }
    else      
    {
      alert("Please correct your numbers and try again.");
      $submit.hide();
    }
    
  }
  
  });

$(document).ready(function () {
  
  findDay();
  
  function findDay() {
    var d = new Date($('#Field62').val());
    var weekday = new Array(7);
    weekday[0] = "Sunday";
    weekday[1] = "Monday";
    weekday[2] = "Tuesday";
    weekday[3] = "Wednesday";
    weekday[4] = "Thursday";
    weekday[5] = "Friday";
    weekday[6] = "Saturday";
    var n = weekday[d.getDay()];
    $('.dayWeek select').val(n);
    $('.dayWeek select').trigger('change');
  }
  
  $('.WORK').on('change', 'input', findDay);
  
});

1 0
replied on October 6, 2016

Hi Jason,

The above code block you've put together seems to work for me, or at least the replace characters function in the table does as I don't know what the rest is supposed to do.

I'd copy your current script from your form that works into notepad as a backup, then paste the above into your form and give it a try.

Cheers! Dan

0 0
replied on November 22, 2016

Sorry for jumping in on this thread, but I'm trying to do roughly the same thing, except that I'm pulling data from a look up table. I can't seem to get the code (referenced above) to work in this instance.

When I select a particular department from the drop down, all the fields below are filled with the corresponding data from the SQL table. The number of rows expand according to the number of users in that department. In the SQL table, the domain precedes the user names like this: domain\username. I'm wanting to automatically remove the "domain\" portion and end up with just the username in that field.

Might you have a suggestion?

 

Thanks,

Michael

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.