Welcome to the nuBuilder forums!
Please register and login to view forums and other content only available to registered users.
Please register and login to view forums and other content only available to registered users.
nuBeforeClone in nuBuilderPro v3.0?
-
- Posts: 20
- Joined: Fri Aug 01, 2014 2:26 pm
nuBeforeClone in nuBuilderPro v3.0?
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
Tried the nuBeforeClone() functuon in Javascript Tab for Custom Code.
Nothing happened.
I wonder wherther similar command is available in V3.0
-
- Site Admin
- Posts: 2781
- Joined: Mon Jun 15, 2009 2:23 am
- nuBuilder Version: 4.5
- Been thanked: 1 time
Re: nuBeforeClone in nuBuilderPro v3.0?
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.
You will need the latest update of nuBuilderPro (created today).
Steven
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#');
}
Steven
-
- Posts: 20
- Joined: Fri Aug 01, 2014 2:26 pm
Re: nuBeforeClone in nuBuilderPro v3.0?
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
The directory has persmissions for www-data which is the user for apache2.
I see the subdirectories being created in ./tmp directory
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
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 <=======
-
- Posts: 20
- Joined: Fri Aug 01, 2014 2:26 pm
Re: nuBeforeClone in nuBuilderPro v3.0?
Thanks to Steven's suggestion and modification, I managed to get the form variables to change when cloned.
eg:
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()
eg:
Code: Select all
function nuLoadEdit(){
var cloned = '#nu_cloned_record#';
if (cloned > 0){
$('#field1').val('NEW');
$('#field1').change;
$('#field2').val('TEMP');
}
}
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()
-
- Site Admin
- Posts: 2781
- Joined: Mon Jun 15, 2009 2:23 am
- nuBuilder Version: 4.5
- Been thanked: 1 time
Re: nuBeforeClone in nuBuilderPro v3.0?
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..
Steven
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')
-
- Posts: 20
- Joined: Fri Aug 01, 2014 2:26 pm
Re: nuBeforeClone in nuBuilderPro v3.0?
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:
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
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'));
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
-
- Posts: 503
- Joined: Thu May 24, 2012 2:08 am
- Location: Milan, Italy
- Contact:
Re: nuBeforeClone in nuBuilderPro v3.0?
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:
Now you can implement your custom nuBeforeClone() function in Custom Code -> Javascript tab, like in nuBuilder v2:
Hope this helps,
Max.
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);
}
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?');
}
Max.
-
- Site Admin
- Posts: 2781
- Joined: Mon Jun 15, 2009 2:23 am
- nuBuilder Version: 4.5
- Been thanked: 1 time
Re: nuBeforeClone in nuBuilderPro v3.0?
Guys,
I have added "nuOnClone()" to the latest nuBuilderPro Build.
Steven
I have added "nuOnClone()" to the latest nuBuilderPro Build.
Steven
-
- Posts: 20
- Joined: Fri Aug 01, 2014 2:26 pm
Re: nuBeforeClone in nuBuilderPro v3.0?
Thanks both for your quick solutions.
I still have issue in getting this to work though.
I even tried two functions nuBeforeClone() and nuAfterClone():
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.
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;
}
}
1. In nuBeforeClone();
Code: Select all
nuSetHash('pr_status','NEW');
2. In nuBeforeClone();
Code: Select all
$('#pr_status').val('NEW');
3. In nuAfterClone();
Code: Select all
nuSetHash('pr_status','NEW');
4. nuAfterClone();
Code: Select all
$('#pr_status').val('NEW');
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.
Code: Select all
nuBuildForm(w);
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;
}