A Great feature of the clone button or the nuCloneAction function would be the ability to pass a string that contains the field names of the fields that I want to be blanked out when cloning a record. For example:
A Date field, or some other required user field, or fields that when I click clone would clone the current record but clear the DOM model form data off the screen.
IE:
fieldlisttoclear ='ord_orderdate, ord_billingamt, ord_comments';
nuCloneAction(fieldlisttoclear);
or have it include my own JavaScript file that I could customize to do whatever I wanted it to. IE: nuCloneAction(scriptname); Like set certain values on certain fields, like dates that would use the current date or time stamped fields, or some other required fields. Looking at the nuform javascript.js file, I think this would be really easy to implement.
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
The Clone Button feature
Re: The Clone Button feature
Great! Thanks. However, in my model its a two step process. Im veiwing a non-editable form. I want the user to be able to view a record but NOT edit the record initially unless they click an Edit button (which I have that working). Now as part of that edit button in the Custom Code section, I put the following:
So basically The Edit Tax form allows the user to edit the existing data. The Duplicate does the same thing, but its supposed to clear the bill_date field. Odd thing thats happening is I'm seeing the field get cleared BEFORE it opens the new editable form, then the original field data in the bill_date field reappears. So It's almost like the Custom code gets ran, and then the nuform function is actually delayed somehow and that nuform function actually reload the data from somewhere else. So what is that somewhere else and how do I reference that data in my Javascript?
Code: Select all
function clearFields(inputVal) {
var temp;
nuForm("6021e47fd6d285b", nuCurrentProperties().record_id, "", "", "1");
temp = document.getElementById(inputVal);
temp.value = '';
// temp = eval('document.getElementById(inputVal) = ""'); //NOTE: I was trying different ways to blank the field here...
temp = eval('document.getElementById(inputVal).focus()'); // NOTE: this doesn't work either. After the nuform is run and loads, this focus() event has already been done.
return true;
}
Code: Select all
$('#nuCloneButton').hide();
if (nuFormType() == 'edit') {
nuAddActionButton('EditTaxForm', 'Edit TaxForm', 'nuForm("6021e47fd6d285b", nuCurrentProperties().record_id, "", "", "1")');
nuAddActionButton('DupTaxForm', 'Duplicate TaxForm', 'clearFields("tax_billdate")');
}
-
- nuBuilder Team
- Posts: 4305
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 446 times
- Contact:
Re: The Clone Button feature
Another possibility: Disable all object when the form is loaded:
Then, when the Edit button is clicked, call
Code: Select all
nuDisableAllObjects();
Code: Select all
nuEnableAllObjects();
Re: The Clone Button feature
Wow! works like a charm thanks! This could be edited to send a long string of fields to wipe out on the new cloned form, or do some other things based on the parameters passed to it As soon as you save it, it locks the screen again. Great! I updated the code in the function below and added a Clearfields function.
Code: Select all
$('#nuCloneButton').hide();
function clearFields(inputVal) {
var temp;
nuEnableAllObjects();
// alert("input="+inputVal);
if (inputVal != "NO") {
nuCloneAction();
// alert("Cloned");
var flds = inputVal.split ("|");
// alert("Flds="+flds);
var i;
for (i=0; i<flds.length; i++) {
// alert(flds[i]);
temp = document.getElementById(flds[i]);
temp.value = '';
} // for i<flds.length
temp = eval('document.getElementById(flds[i-1]).focus()');
// alert("Changed Stuff...");
nuDisable('cust_1styear');
}
$('#nuEditMyFormButton').hide();
$('#nuDupMyFormButton').hide();
return true;
}
function checkfld(evt, str, mask) {
var mLn = mask.length;
var orgstr = str.value;
var sLn = orgstr.length;
var curstr = evt.key
var validmasks = '#@';
var charCode = (evt.which) ? evt.which : evt.keyCode
if (charCode == 8 || charCode == 37 || charCode == 39 || charCode == 35 || charCode == 13|| charCode == 9) {return false;}
// if user presses left arrow 8 |backspace 37 |right arrow 39| end 35 | home 36 | del 46 | enter=13 |tab=9
if (charCode == 46) {str.value = ""; return evt.preventDefault(); } // if user presses del = delete ALL
if (charCode == 32) {return evt.preventDefault(); } // if user presses space
/* alert(charCode); */
if (sLn < mLn) {
var i=0;
var charmask = mask[sLn+i];
/* alert("CharMask="+charmask+" Str Len="+sLn); */
while (!validmasks.includes(charmask)) {
str.value = str.value + charmask;
if (i>4) {break;}
i++;
charmask = mask[sLn+i];
} /* while */
switch(charmask) {
case "#":
/* alert("# StringChar="+curstr); */
if ((curstr >=0) && (curstr <=9)) { return true;
} else { return evt.preventDefault(); }
break;
case "@":
/* alert("@ StringChar="+str.charAt(sLn)); */
if ((curstr.toUpperCase() >= "A") && (curstr.toUpperCase() <= "Z")) { return true;
} else { return evt.preventDefault(); }
break;
default:
return evt.preventDefault();
break;
} /*switch */
} else { return evt.preventDefault(); } /* if sLn < mLn mask length */
return true;
nuAddActionButton('DupMyForm', 'Duplicate MyForm', 'clearFields("cus_billdate")');
nuAddActionButton('EditMyForm', 'Edit MyForm', 'clearFields("NO")');
nuDisableAllObjects();
nuEnable('EditMyForm');