Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Running length of text field

Locked
Tinka
Posts: 73
Joined: Mon Feb 24, 2014 2:58 pm

Running length of text field

Unread post by Tinka »

Hi

I tried this solution in this post:
http://forums.nubuilder.cloud/viewtopic.p ... ers#p12550.

It does not work for me. Would you please help?

What has the html object to be? I put an input box read-only:

Code: Select all

<input readonly type=text name=bases 
size=3 value="0"> 
The Javascript function is on the Edit form's Javascript tab. I tried both the html-object name or object id form the zzzsys_object table.

Code: Select all

function nuLoadEdit() {
  $('#531dcb7d9bf9567').keyup(function () {
    var max = 30;
    var col = 'grey';
    var len = $(this).val().length;
    if (len >= max) {var col = 'red';}
    $('#bases')
      .text(len)
      .css('color', col);
  });
}
Tinka
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Running length of text field

Unread post by massiws »

Tinka,
your HTML object must have id="bases", so jQuery can select it.

Max
Tinka
Posts: 73
Joined: Mon Feb 24, 2014 2:58 pm

Re: Running length of text field

Unread post by Tinka »

Max,

thank you for your reply. My html object has the field name "bases", but do you mean the object id in the zzzsys_object table?

Is the syntax in the Javascript ok?

Tinka
Tinka
Posts: 73
Joined: Mon Feb 24, 2014 2:58 pm

Re: Running length of text field

Unread post by Tinka »

Got it working! You can close the topic.
I changed the object name of the object with keyup from the id in the system table to the field name!

Code: Select all

function nuLoadEdit() {
  $('#prim_sekvens').keyup(function () {
    var max = 30;
    var col = 'grey';
    var len = $(this).val().length;
    if (len >= max) {var col = 'red';}
    $('#bases')
      .text(len)
      .css('color', col);
  });
}
Tinka
Tinka
Posts: 73
Joined: Mon Feb 24, 2014 2:58 pm

Re: Running length of text field

Unread post by Tinka »

Any idea how to save the value of the running text length to the field afterwards (on After Save Custom Code)?
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Running length of text field

Unread post by massiws »

Tinka, do you want to store the length value in database?
If so, you should create a new field in your table and configure a text object on your form to map this field; alternatively, configure your "bases" field to map the new created DB field.
Then add a new line in your function to store the length value in DB field:

Code: Select all

function nuLoadEdit() {
    $('#prim_sekvens').keyup(function () {
        var max = 30;
        var col = 'grey';
        var len = $(this).val().length;
        if (len >= max) {var col = 'red';}
        $('#bases')
            .text(len)
            .css('color', col);
    });
    $('#my-db-field-name').val(len);
}
Max
Tinka
Posts: 73
Joined: Mon Feb 24, 2014 2:58 pm

Re: Running length of text field

Unread post by Tinka »

Thank you, I had figured it out.
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Running length of text field

Unread post by massiws »

.
Locked