Copy field to another Field after Edit

Questions related to using nuBuilder Forte.

Copy field to another Field after Edit

Unread postby oli » Sat Apr 17, 2021 5:27 pm

Hi All,

what is the best way to copy the value of a textarea field (textarea1) to another textarea field (textarea2) on the same form after textarea1 was changed?

Is there any simple solution available?

Thanks in advance and best regards,
Oli
oli
 
Posts: 43
Joined: Sat Mar 20, 2021 11:52 pm
nuBuilder Version: 4.5

Re: Copy field to another Field after Edit

Unread postby kev1n » Sat Apr 17, 2021 5:30 pm

Hi Oli,

Add a Custom Event onchange to your first Textarea object and call:
Code: Select all
$('#other_text_area_id').val($(this).val()).change();
Attachments
onchange.png
onchange.png (6.65 KiB) Viewed 107 times
kev1n
nuBuilder Team
 
Posts: 1704
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Copy field to another Field after Edit

Unread postby oli » Sat Apr 17, 2021 6:00 pm

Thanks a lot!
oli
 
Posts: 43
Joined: Sat Mar 20, 2021 11:52 pm
nuBuilder Version: 4.5

Re: Copy field to another Field after Edit

Unread postby oli » Sat Apr 17, 2021 8:08 pm

Additionally I tried to set a button to hidden if a specific value of a select field was choosen.
This is was I added to the select object and if the value is "in Planung" the Button should not be visible anymore.
But I guess I still have some errors in the code and I couldn't find an example how to get the value for a specific SELECT object and use it in an IF statement.

screenshot.jpg
screenshot.jpg (59.04 KiB) Viewed 104 times


BR and thanks in advance, Oli
oli
 
Posts: 43
Joined: Sat Mar 20, 2021 11:52 pm
nuBuilder Version: 4.5

Re: Copy field to another Field after Edit

Unread postby kev1n » Sat Apr 17, 2021 8:20 pm

Try this:

Code: Select all
function stringsAreEqual(a, b) {
   var a = escape(a).replace(/%20/g, '').replace(/%A0/g, '');
   var b = escape(b).replace(/%20/g, '').replace(/%A0/g, '');
   return a == b;
}

nuShow('run_angebot_print',  ! stringsAreEqual(this.value, 'in Planung') );


If the text and values are different, you need to retrieve the text like this:

Code: Select all
$("#your_select_id option:selected").text();
kev1n
nuBuilder Team
 
Posts: 1704
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Copy field to another Field after Edit

Unread postby oli » Sat Apr 17, 2021 8:36 pm

it works :-)
Thank you!
oli
 
Posts: 43
Joined: Sat Mar 20, 2021 11:52 pm
nuBuilder Version: 4.5

Re: Copy field to another Field after Edit

Unread postby oli » Sun Apr 18, 2021 8:10 pm

Since I have to check various status values and the button should be hidden after the form was accessed it would be easier to hide the button with PHP.
Is there a way to conditionally hide or show objects with PHP as well?
oli
 
Posts: 43
Joined: Sat Mar 20, 2021 11:52 pm
nuBuilder Version: 4.5

Re: Copy field to another Field after Edit

Unread postby kev1n » Sun Apr 18, 2021 9:36 pm

You will have to use JavaScript. But you could prepare it in BE and run in with nuAddJavascript
kev1n
nuBuilder Team
 
Posts: 1704
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5


Return to General

Who is online

Users browsing this forum: No registered users and 21 guests