I have this form, an official form (a character sheet for use at an Organized Play Event for a role-playing game, if it matters to anyone), that someone kindly turned into a fillable PDF form. I asked a question earlier about checkboxes and auto-calcualtions, and got that to work...but now I need to account for another variable (situational doubling of the Proficiency Bonus) in some of my calculations. Unfortunately, this variable is not represented anywhere on this form, and I can't just add fields to the form (it being an official form, at least when printed). Without adding more fields to the (printed) form, how can I account for this additional variable?
I thought about just allowing the user to override the auto-calculation by typing in the field, but I can't figure out how to make that happen. Is this a good solution? Is this relatively simple to code?
If your answer involves adding code to my form, please include a code snippet I can modify, and a description of where I should insert it into my existing code, or if there is somewhere else I need to be adding it instead.
Code Sample:
//check bonus = stat bonus + applicable proficiency bonus
var profUse = this.getField("SklAcrProf").value;
var stat = Number(this.getField("DEX1").value);
var profVal = Number(this.getField("Proficiency Bonus").value);
var check = Number('-2');
if (profUse != "Off"){
check = stat + profVal;
}
else{
check = stat;
}
event.value = check;
If the form only needs to remain the same, when printed, the simplest solution may be to go ahead and add the fields that you need. You can set them up, so that they are "visible but doesn't print". This option can be selected in the Form Field drop-down list, in the Text Field Properties, General Tab, under Common Properties.
This way, you can still incorporate the data in your formulas, but it has no affect on the printed document.
Related
I got a form with lots of fields and many scripts so I broke it down to my very fundamental problem with this example:
Before printing I check if everything is filled out with:
Seite1.execValidate();
The validate XML source of the field:
<validate nullTest="error" scriptTest="error"/>
When clicking on the top-button I want different things to happen.
For example:
field.rawValue = "";
or (if it's a decimal field)
//isPauschal was set earlier to either true or false
field.value.decimal.leadDigits = (isPauschal)?"4":"2";
But then this happens:
Field goes blue (=it is empty) when setting its value to "" - this I want only to happen when I'm validating with the print-button.
Now I found a workaround:
field.mandatory = "";
field.rawValue = "";
field.mandatory = "error";
But if I were to write this every time I changed something that would trigger this my code would look pretty bad and much more confusing.
Can someone help me?
What could I do to easily validate my fields before printing and still being able to change them around with js at runtime without them making strange colors. ;)
I don't want to validate them individually - I wish to keep something like the execValidate() command so it automatically checks all the fields in a subform.
Let me know if you need any more information!
is there such a way? I've had little success in using the .innerHTML method.
Some context, I'm new to Javascript, and I'm trying to make a text RPG as a bit of a fun project using what I know in HTML, CSS, and Javascript... The latter of which I've had not too much experience with yet.
The function would have to modify a element, inserting a snippet that asks for a name for a character, and the form along with a submit button... Then take what they enter and modify a JSON variable that'll essentially function as a character file.
It all has to be done client side as well, if it can be helped... Any way someone might help? Or of not give an outright solution, point me in the right direction?
You can use cookies to store information on the browser, such as a player name. Example is
document.cookie='PlayerName = ThatOneGuy';
You can see more details at https://developer.mozilla.org/en-US/docs/Web_Development/HTTP_cookies
Below, I've written some simple dom manipulation, that creates a form, an input, and when the input loses focus stores whatever is in the input, into either a cookie or localStorage.
There are several things missing, like checking if the input actually had a value, along with zero error checking.
You can find out more about localStorage here, here and here. You can find out more about cookies here.
function init_form(){
var form = document.createElement('form');
var input = document.createElement('input');
input.setAttribute('id', 'player_name');
input.setAttribute('placeholder', ' Enter Characters Name');
input.setAttribute('type', 'text');
form.appendChild(input);
document.appendChild(form); //or document.getElementsByTagName('body')[0].innerHTML += form;
input.addEventListener('blur', store_name_in_local_storage, false);
}
function store_name_in_local_storage(){
var name = document.getElementById('player_name');
//check to see if browser supports local storage if it does, use it, if it doesn't use cookies
if(!window.localStorage){
document.cookie = 'player_name ='+ name;
}else{
localStorage.setItem('player_name', name);
}
}
function get_player_name(){
var name = '';
//retrieve the cookie or local storage name
if(!window.localStorage){
name = document.cookie
}else{
name = localStorage.getItem('player_name');
}
}
Note about the links: Since your new to javascript I would use the second link on localStorage, the first is very good documentation about how to use it, and the third is the actual specification page for the feature.
Also, I included the code for setting cookies to be thorough, not because you really need it. localStorage is supported all the way back to IE8 and in all the other major browsers.
If you want to check the compatibility of any javascript/html5 feature I suggest here.
Good Luck!
So I've made this search that does what its supposed to do front-end wise. However, when submitting I'd like the query to ignore commas.
Right now I'm using commas to make a comma separated search. The whole thing is, when I submit; the comma's are included and thus messes up my search values.
Is there any way to ignore comma's upon submit?
Example: Searching [Example][Test] will actually return Example,Test.
I've made a fiddle here
Any suggestions and help is greatly appreciated.
var firster = true;
//capture form submit
$('form.nice').submit(function(e){
if(firster){
// if its the first submit prevent default
e.preventDefault();
// update input value to have no commas
var val = $('input').val();
val = val.replace(/,/g, ' ');
$('input').val(val);
// let submit go through and submit
firster = false;
$(this).submit();
}
});
DEMO
Looking at your profile, I'm guessing you're using python as a server-side language. The issue you're trying to solve is best dealt with server-side: never rely on front-end code to escape or format data that is being used in a query... check Bobby Tables for more info
Anyhow, in python, you could try this:
ajaxString.replace(",","\", \"")
Thiis will replace all commas witIh " OR ", so a string like some, keywords is translated into some", "keywords, just add some_field IN (" and the closing ") to form a valid query.
Alternatively, you can split the keywords, and deal with them separately (which could come in handy when sorting the results depending on how relevant the results might be.
searchTerms = ajaxString.split(",")
>>>['some','keywords']
That should help you on your way, I hope.
Lastly, I'd suggest just not bothering with developing your own search function at all. Just add a google search to your site, they're the experts. There is just no way you, by yourself, can do better. Or even if you could, just imagine how long it'd take you!
Yes, sometimes a company will create their own search-engine, but only if they have a good reason to do so, and have the resources such an endevour requires. Programming is often all about being "cleverly lazy": Don't reinvent the wheel.
The professional edition licence of Salesforce does not allow the use of APEX code or Workflow unless purchased separately.
I have a requirement to clean up text in Salesforce that was input via on a web form that I do not control. The client wants to fix any text with ALL CAPS or missing sentence capitalisation.
I've seen this answer on a this question Is it possible to add style to a field in Salesforce? which uses javascript within a custom side bar component . It assumes that the transformation is to occur as the user types the data into the application. My requirement might allow for a custom salesforce button to invoke the action on the fields as the data will populated by an automated process.
Assuming I were to follow the same pattern I would have to find a way to reliably detect and fix bad formatting within a string.
Is there a good way to do this with javascript within salesforce?
I have found a way to get closer to what I need thanks to a regular expression and the AJAX toolkit.
I have created a custom detail button that invokes javascript OnClick.
The code takes the current lead and searches the Description field for any strings of >2 characters that are uppercase, within the characther class [A-Z]. Each time it matches a string it will replace that string with a lowercase version of itself.
Once the string has been 'cleaned' the lead can be updated.
{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")} //adds the proper code for inclusion of AJAX toolkit
var url = parent.location.href; //string for the URL of the current page
var updateRecords = []; //array for holding records that this code will ultimately updated
var re = new RegExp('[A-Z]{2,}', 'g');
var inputString = "{!Lead.Description}";
var matches = inputString.match(re);
if(matches != null){
for(var i = 0; i< matches.length;i++){
inputString = inputString.replace(matches[i], matches[i].toLowerCase());
}
var update_Lead = new sforce.SObject("Lead"); //create a new sObject for storing updated record details
update_Lead.Id ="{!Lead.Id}"; //set the Id of the selected Lead record
update_Lead.Description = inputString;
updateRecords.push(update_Lead); //add the updated record to our array
}
result = sforce.connection.update(updateRecords); //push the updated records back to Salesforce
parent.location.href = url; //refresh the page
I based this code on some that I found Salesforce: Custom Button to Execute JavaScript
It should be possible to amend this code to work on any Salesforce object and to work over a selection of fields. The code that does the replacement could be moved into a function to make this easier.
I'm looking for a way to get all the information out of localStorage. The trouble I'm having is I don't know what the data will be as it is user generated.
So here what happens, a user inputs some text, it uses javascript to manipulate it depending on what check boxes they have ticked on the input form. these boxes are for symbols for example if they tick the box for # then the text + the #At (symbol then word) will be placed in local storage with the other half of the pair as a Boolean (1 or 0 in this case) representing whether its been checked.
the exact pair would look like this:
someString..#At | 1
someString..#Hash | 0
etc.
It should also be noted that this is intended to be used in a Chrome Extension so compatibility in other browsers is not a requirement for me (although it could well be usful to others reading this as I can't find anything else covering it on the web).
So, if there anyway I can extract all the values in localStorage without actually knowing the name of each key?
Is it possible to use any kind of wild card or regular expression maybe, I have tried this but should make it work using a for loop.
Thanks,
Wez
window.localStorage.key is the solution.
Example:
var i = 0,
oJson = {},
sKey;
for (; sKey = window.localStorage.key(i); i++) {
oJson[sKey] = window.localStorage.getItem(sKey);
}
console.log(oJson);