Page 1 of 2
nuBeforeClone in nuBuilderPro v3.0?
Posted: Sun Aug 31, 2014 10:34 pm
by jkdev
I need to modify some fields in a form when Clone button is pressed before a fresh forn is displayed.
Tried the nuBeforeClone() functuon in Javascript Tab for Custom Code.
Nothing happened.
I wonder wherther similar command is available in V3.0
Re: nuBeforeClone in nuBuilderPro v3.0?
Posted: Tue Sep 02, 2014 1:12 am
by admin
jkdev,
You can make changes to a cloned record as the newly cloned record loads - before it is saved.
Just by checking if it a record that is cloned. And then doing what you want.
Code: Select all
function nuLoadEdit(){
console.log('#nu_cloned_record#');
}
You will need the latest update of nuBuilderPro (created today).
Steven
Re: nuBeforeClone in nuBuilderPro v3.0?
Posted: Tue Sep 02, 2014 4:30 am
by jkdev
Thanks a lot Steven.
I am trying to update via the Update button but it does not detect the updated files.
When I press the button first, it returns internal server error. Second time onwards it just lists
Code: Select all
RESULT: SUCCESS
0 File(s) updated
No Column(s) Added
No Column(s) Changed
No SQL errors
No Warnings
The directory has persmissions for www-data which is the user for apache2.
I see the subdirectories being created in ./tmp directory
Code: Select all
-rw-r--r-- 1 www-data root 0 2014-08-09 10:35 file-uploads-go-here
drwxr-xr-x 3 www-data www-data 4096 2014-08-23 15:05 GIT_2014_08_23_15
drwxr-xr-x 3 www-data www-data 4096 2014-09-02 07:53 GIT_2014_09_02_07 <=======
drwxr-xr-x 3 www-data www-data 4096 2014-09-02 08:00 GIT_2014_09_02_08 <=======
Re: nuBeforeClone in nuBuilderPro v3.0?
Posted: Tue Sep 02, 2014 9:13 pm
by jkdev
Thanks to Steven's suggestion and modification, I managed to get the form variables to change when cloned.
eg:
Code: Select all
function nuLoadEdit(){
var cloned = '#nu_cloned_record#';
if (cloned > 0){
$('#field1').val('NEW');
$('#field1').change;
$('#field2').val('TEMP');
}
}
However I have buttons displayed on the cloned form based on hash values.
When I click on "Clone" I was shown the correct value via Javascript Console.
However the hash varoables (#var_name) them seleves give back original value.
It appears that hash variable replacement happens before coming to nuLoadEdit()
Re: nuBeforeClone in nuBuilderPro v3.0?
Posted: Wed Sep 03, 2014 12:10 am
by admin
jkdev,
Are you trying to show the buttons or hide them? (Because you can obviously use JavaScript to make them hidden).
The other alternative is to set those hash variables before you run the clone button, with nuSetHash();
And create an Extra Actionn Button that replaces the Clone button with code like this..
Code: Select all
nuSetHash('hashvariable', value);
nuCloneForm(this, formid, nuGetHash('record_id')
Steven
Re: nuBeforeClone in nuBuilderPro v3.0?
Posted: Wed Sep 03, 2014 1:42 pm
by jkdev
Steven,
I could not still make it work.
Here is what I want to do:
1. When pr_status=POSTED I need to hide the Save button. I set display condition to hide Save button only when pr_status=POSTED via (#pr_status#)
2. pr_status=POSTED should be changed to pr_status=NEW when cloned
3. When pr_status=NEW Save button should be visible.
The problem happens when #pr_status# does not get changed in to NEW when in step 3 and therefore the Save button does not get visible.
I created a new button and added following:
Code: Select all
nuSetHash('pr_status','NEW');
nuCloneForm(this, '#FORM_ID#', nuGetHash('record_id'));
The nuSetHash apears to be changing the pr_status field to NEW (as observed when the record/field is displayed after cloning). So that part seems to be working.
Hower the hash replacement which occurs on cloned record loading still seem to have the value substituted as pr_status=POSTED. Therefore the Save button does not get displayed.
Am I missing something?
jk
Re: nuBeforeClone in nuBuilderPro v3.0?
Posted: Thu Sep 04, 2014 5:31 am
by massiws
My two cent alternative.
To add the "old" nuBuilder v2 nuBeforeClone() function in nuBuilderPro is pretty simple (obviously hacking nuBuilder core):
in
nucommon.js edit the
nuCloneForm() function (lines 1095-1107) like this:
Code: Select all
function nuCloneForm(pThis, formID, recordID) {
// Check if nuBeforeClone() is defined by user
if (typeof nuBeforeClone == 'function' && nuBeforeClone() == false) {
return;
}
var w = new nuWindow();
w.form_id = formID;
w.title = $('title').html();
w.call_type = 'cloneform';
w.cloned = '1';
w.record_id = recordID;
w.tip = 'Edit';
window.nuSession.breadCrumb.pop(); //-- remove breadcrumb before another is added
nuBuildForm(w);
}
Now you can implement your custom nuBeforeClone() function in
Custom Code -> Javascript tab, like in nuBuilder v2:
Code: Select all
/*
* This function must return TRUE to allow or FALSE to stop cloning.
*/
function nuBeforeClone() {
// Make your job
return confirm('Do you want to clone this record?');
}
Hope this helps,
Max.
Re: nuBeforeClone in nuBuilderPro v3.0?
Posted: Fri Sep 05, 2014 5:20 am
by admin
Guys,
I have added "nuOnClone()" to the latest nuBuilderPro Build.
Steven
Re: nuBeforeClone in nuBuilderPro v3.0?
Posted: Sat Sep 06, 2014 2:21 pm
by jkdev
Thanks both for your quick solutions.
I still have issue in getting this to work though.
I even tried two functions nuBeforeClone() and nuAfterClone():
Code: Select all
function nuCloneForm(pThis, formID, recordID){
// Check if nuBeforeClone() is defined by user and it returns TRUE
if (typeof nuBeforeClone == 'function' && nuBeforeClone() == false) {
return;
}
var w = new nuWindow();
w.form_id = formID;
w.title = $('title').html();
w.call_type = 'cloneform';
w.cloned = '1';
w.record_id = recordID;
w.tip = 'Edit';
window.nuSession.breadCrumb.pop(); //-- remove breadcrumb before another is added
nuBuildForm(w);
// Check if nuAfterClone() is defined by user and it returns TRUE
if (typeof nuAfterClone == 'function' && nuAfterClone() == false) {
return;
}
}
These are the things that I tried:
1. In nuBeforeClone();
Result: No change to either value on the form nor the hash variable #pr_status#
2. In nuBeforeClone();
Result: form value changed before cloning. But when form was refreshed after cloning the value was reset to what was on the original form
3. In nuAfterClone();
Same result as 1 above
4. nuAfterClone();
Result: form value got changed to NEW. However has variable #pr_status# remains at the former value.
So my original problem is not solved ie. I cannot get the hash variable #pr_status# to get changed so that I can control the display of Save button on the value of #pr_status# once the record is cloned.
I believe the issue here may be that we do all the changes before and after the object gets created.
If you try to change values in nuBeforeClone(); the object 'w' has not been created by then and no value get set in the new object.
If you try to change values in nuAfterClone(); then the object 'w' has been created and value can be changed but probably the hash_variables have been already changed when the form data was read in and no further change can be done to them.
Can you help me to understand how the nuSetHash works.
Code: Select all
function nuSetHash(name, value){
nuFORM[name] = value;
}
Re: nuBeforeClone in nuBuilderPro v3.0?
Posted: Tue Sep 09, 2014 12:05 am
by admin
jkdev,
Are you saying nuOnClone() wont work?
Steven