I am using selec2.js. While entering values in drop down i am validating input text for special characters. After validating, i am returning true of false from validation function. If not valid i want to show error 'Special character not allowed' below input box.
$jQ("selectDropDown").on("select2-selecting", function(e) {
isValid =validateValueOnAdd(e.val, dataTypeId);
if(!isvalid){
{formatNoMatches:"not valid"};
return false;
}
Can someone help???
Related
I have a simple client script to validate select field, even if I put only false to return its always validate ( you can pass to next field, there is no focus)
Is it a known problem with that select fields?
function validateField(scriptContext) {
var field = scriptContext.fieldId;
if (field === 'custbody_select') {
return false
}
return false
}
I'm trying to number format the caller cell for a custom function, specifically to replace the scientific notation with a numeric format for big numbers and then auto fit the column width.
An idea is to check the cell text for presence of "E", but the issue is that the formatting code seems to run before the result is written to the cell (which kind of makes sense, honestly), so I'm doing a comparison and set the cell format accordingly. Setting the cell format works fine (it doesn't need the result written to the cell), but auto fitting the column width doesn't.
Here is the custom function code:
getData returns a number (or an error string) from an API call
formatNumber should set the cell number format and autofit the column width, based on the returned number.
async function Test(symbol, metric, date, invocation) {
const address = invocation.address;
return await getData(symbol, metric, date)
.then(async (result) => {
if (!isNaN(result) && result > 99999999999) {
await formatNumber(address);
}
return result;
})
.catch((error) => {
console.log("error: " + error);
return error;
});
}
Here is the formatNumber code.
range.text returns #BUSY, which means the data is still retrieved from the API when the function runs. Due to this, autofitColumns will set the column size based on "#BUSY" string length.
async function formatNumber(address) {
await Excel.run(async (context) => {
const formats = [["#,##0"]];
const range = context.workbook.worksheets.getActiveWorksheet().getRange(address);
range.load("text");
await context.sync();
console.log("range.text: " + range.text);
range.load("numberFormat");
await context.sync();
range.numberFormat = formats;
range.format.autofitColumns();
await context.sync();
});
}
Any ideas?
Thank you for your time,
Adrian
The custom functions return value will be set to the cell after the function is returned.
I suggest your add-in register an onChanged event handler on the worksheet, and call format.autofitColumns() to handle the event;
On the page that I am testing, a user can have a single currency or multiple currencies (i.e EUR and USD)the currency/currencies will appear in the same div at the top of the page.
If a user has multiple currencies, a tab for each currency will appear further down the page, if a user has only one currency, no tabs will appear (as there is no need for the user to switch tabs).
I am able to test multi currency users by checking to see if the text contained in the header matches the text contained in the currencies tabs.
However, as no tabs appear for a single currency, I'm not sure how to test this.
For example, if I have only a 'EUR' currency, is there a way to do something like
if element(by.className("currencies"))contains 'EUR'
&& doesn't contain 'USD' && doesn't contain 'GBP'
expect element(by.className("tabs").toDisplay.toBeFalsy()
This is the code for the page object file
this.checkCurrency = function(currency) {
var checkBalance = element(by.className("balances"));
checkBalance.getText().then(function (text) {
if (text.indexOf("GBP" && "EUR")>= 0) {
expect(element.all(by.linkText("GBP")).isDisplayed()).toBeTruthy();
console.log("EUR GBP buyer");
}
else if (text.indexOf("GBP" && "USD")>= 0) {
expect(element.all(by.linkText('USD')).isDisplayed()).toBeTruthy();
console.log("USD GBP buyer");
}
else
{
console.log("false");
}
});
};
From your description I'm not quite sure where the failure is. In general you want to keep this kind of logic out of your page object. Your test should understand what state the page should be in and call different functions. I know that's not always possible, but it works out so much better if you can. Here is some general condition advise that should help.
You can catch the success state and a failed state of a promise. Most people use the pass function, but forget about the fail function.
promise.then(passFunction, failFunction)
You can use this in several different ways. If you realize that almost everything in protractor is returning a promise.
Example:
element(by.className("currencies")).getText()
.then(
function(text) {
//check on something
},function(error){
//don't check on something
if(someCondition) {
throw error;
} else {
//the test continues
}
});
You can even do it with and expect
expect(element(by.className("currencies")).getText()).not.toContain("EUR")
.then(
function(passed) {
//check on something
},function(failed){
//don't check on something
if(someCondition) {
throw failed;
} else {
//the test continues
}
});
Or a simple findElement
element(by.className("currencies"))
.then(
function(element) {
//check on something
},function(error){
//don't check on something
if(someCondition) {
throw failed;
} else {
//the test continues
}
});
I'm trying to make a simple domain check before sending an email on gmail. So I wrote the below code:
//debugger;
document.addEventListener('blur', function(event){
var target = event.target;
if (target.name !== 'to' && target.name !== 'cc' && target.name !== 'bcc') return;
console.log(target.name, ":", target.value);
},true); // event listener blur
I can see target.name on console window like "to:","cc:", or "bcc:". However, can not get value at all. Any advice appreciated. Thank you.
(What I believe to be)
The problem
Each time you add an address in recipient's field (to, cc, bcc), a new input field is appended to the element holding the recipient address (e.g. with name="to" and value=<email#addree.ss>). Furthermore, an empty textarea is always appended at the end and its purpose is to capture any new email address you might want to add (convert it to an input field as mentioned before and emptying itself again).
Use case:
You see 3 email addresses in the to field.
You click in the field (so it gains focus).
You click away (so it losses focus).
The following gets logged: to: (i.e. no value).
What actually happens, is that you log the value of the empty textarea at the end of the to field.
The solution:
Every time you catch a blur event related to a recipient's field, act upon (e.g. log) the values of all elements whose name equals the blurred field's name.
I know it doesn't make much sense, so here is an example:
document.addEventListener("blur", function(evt) {
var tname = evt.target.name;
if ((tname !== "to") && (tname !== "cc") && (tname !== "bcc")) {
return;
}
var elemList = document.querySelectorAll("[name='" + tname + "']");
[].slice.call(elemList).forEach(function(elem) {
console.log(elem.name, ":", elem.value);
});
}, true);
I am stumped. I have an input field in an xpage where I added a custom validator. I can not get the custom validator to fire no matter what I try. There is a also validateRequired which works as expected. The error message is sent to a "Display Error" control, clientside validation is disabled. The goal of the custom validator is to check if a valid date has been entered. After I get it working, I also plan to add other complicated validation such as checking valid day of the week.
The print statements work correctly, as in "inside true" shows in the console for a valid date, and "inside false" shows for an invalid date. If I add a test print statement after the if statement, it doesn't not execute as you would think. For either condition, the message does not display, and the page is submitted.
I have tried using both getValue() and getSubmittedValue. I have also tried returning a facesMessage and a string. I am also very open to better ways to do this.
<xp:inputText id="datepicker" styleClass="datepicker"
value="#{viewScope.arrivalDate}"
defaultValue="#{javascript:statusBean.arrivalDate}"
disableClientSideValidation="true">
<xp:this.validators>
<xp:validateRequired message="Please enter the arrival date">
</xp:validateRequired>
<xp:customValidator message="err" loaded="true">
<xp:this.validate><![CDATA[#{javascript:var datepicker = getComponent("datepicker").getSubmittedValue();
var testDate = #IsTime(#TextToTime(datepicker));
print("testDate=" + testDate);
if(testDate == 0){
print("inside false");
return false;
} else if(testDate == 1){
print("inside true");
return true;
}}]]>
</xp:this.validate>
</xp:customValidator>
</xp:this.validators>
I haven't tried with a custom validator, but here's the SSJS I put in the validator property for a sample demo at LUGs last year:
<xp:this.validator>
<![CDATA[#{javascript:var sv = this.getSubmittedValue();
print ("Checking submitted value for input1 '" + sv + "' is more than 5 characters");
print ("Value for input1 is " + this.getValue());
if (sv.length < 5) {
var msgStr = "You must enter your FULL name, which will be more than 5 characters!";
var msgObj = new javax.faces.application.FacesMessage(javax.faces.application.FacesMessage.SEVERITY_ERROR, msgStr, msgStr);
facesContext.addMessage(getClientId(this.getId()), msgObj);
this.setValid(false);
}}]]>
</xp:this.validator>
Note that it adds the facesMessage and also sets the component's valid property to false.
The customValidator must return a string with the error message in it - and not true or false.
So in your case, do this instead:
<xp:customValidator message="err" loaded="true">
<xp:this.validate><![CDATA[#{javascript:
var datepicker = getComponent("datepicker").getSubmittedValue();
var testDate = #IsTime(#TextToTime(datepicker));
print("testDate=" + testDate);
if(testDate == 0){
print("inside false");
return "Invalid date";
}
}]]></xp:this.validate>
</xp:customValidator>
Here's my version with using xSnippet - postValidationError.
<xp:customValidator>
<xp:this.validate><![CDATA[#{javascript:
if (#IsTime(#TextToTime(#Trim(value))) == 0){
postValidationError(this, "Please enter a valid Date/Time")
}
}]]></xp:this.validate>
</xp:customValidator>