I am doing signup page's uitextfields validation programmatically. I have given a single label separately under signup button where it shows the error message.
I have given first name text wrong so that label shows "Please enter valid first name" and I have done the same with Last name and now the message "Please enter valid second name" overlaps the first name error message.
How to get two error messages separately using single label?
you can just change the text of the label while showing the Error message
For Eg:
if (**firstNameTextWrong**)
{
lbl.text=#"Please enter valid first name";
}
else if (**secondNameTextWrong**)
{
lbl.text=#"Please enter valid second name";
}
else
{
//do the right part here
[lbl setHidden:YES];
}
Related
I have an add button that adds entries to a txt file, and a jlist that is populated by the txt file. The jlist is refreshed immediately when an entry is added. The add button utilizes showinputdialog for the user to add an entry and here lays the problem:
1) I understand that when the cancel button is pressed, joptionpane returns null. How do i make it so that it doesn't actually add "null" to the txt file and the jlist when i press cancel?
2) Also, similar problem, if I don't input anything and press the enter button, the program adds an empty entry to the txt file that also show up on the jlist. How do I make it so that if no input is entered and the ok button is pressed, a prompt pops up and tells the user to enter a valid input?
Here's what I've got so far...
#Override
public void actionPerformed(ActionEvent e)
{
String entry = "\n" + JOptionPane.showInputDialog(null, "Enter part number");
if(entry.equals(null))
{
JOptionPane.showMessageDialog(null, "Invalid entry", "Blank entry!", JOptionPane.WARNING_MESSAGE);
}
The if statement here actually doesn't do anything and I don't know why...
In your problem number 2.. also trim your input. you can condition your input like this:
String entry = JOptionPane.showInputDialog(null, "Enter part number");
if(entry == null){ // if the user press cancel;
return;
}
entry = entry.trim();
if(entry.equals("") || entry.isEmpty()){
JOptionPane.showMessageDialog(null,"Please enter a valid input!");
return;
}else{
entry = "\n" + entry;
}
I have a string :"Send email to my friend". I want to have this string as a title of a button. But I just want to show only "Send email" and hide the rest of string. is it possible to do that?
You can Add title to button as the text is never changing.
[myButton setTitle:#"Send email" ];
Or if you are getting this text at runtime, you need to do the string manipulation. Class reference for this is available at https://developer.apple.com/library/ios/documentation/uikit/reference/UILabel_Class/Reference/UILabel.html
Just display the first x characters of the string.
[mystr substringToIndex:3];
I am new to selenium, and when testing a web application I want to check when credentials are wrong the message in alert which gets displayed and the error message that is displayed on the page after accepting the alert are same or not please can anybody help me how can I do this
I have handled alert using
web.swichto.alert().accept
but I want to compare the message that alert displays and the error message that is displayed in that page like
Error: Invalid User ID/Password Or Network Is Down!
and message in alert box like
Invalid username/password
thanks in advance
you can store text present in the alert into a variable as follows,
String msg_in_alert=driver.switchTo().alert().getText();
then you can use assert to compare,
Assert.assertEquals(driver.findElement(By.cssSelector("selector_of_error_element")).getText().compareTo(msg_in_alert), true);
"true" specifies that the text should match..
If text does not match,it will result in step failure...
WebElement element = _driver.findElement(By.xpath("//span[#class='ng-binding error-class ng-hide']"));
element.getText();
if(element.equals("Recall and Volume data does not exist for calculation. Please upload the data.")){
System.out.println("true");
}else{
System.out.println("false");
}
WebElement mandmessActionName = driver.findElement(By.xpath("//*[#id='container']/div/form/div[1]/div/fieldset/div[1]/div/span[1]"));
String mandmessActionName1 = mandmessActionName.getText();
if (mandmessActionName1.equals("Action Name is required."))
{
System.out.println("true");
}
else
{
System.out.println("false");
}
I have a fillable PDF file. I would like to require that a TextBox has a value when the user saves the PDF document i.e. the value is not blank.
Here is what I tried:
(1) Setting the "Required" field on the "TextBox".
PROBLEM: That didn't do much except color the textbox red.
(2) I tried to use the following code in the "onBlur" event:
f = getField(event.target.name)
if (f.value.length == 0)
{
f.setFocus()
//Optional Message - Comment out the next line to remove
app.alert("This field is required. Please enter a value.")
}
PROBLEM: If the user never clicks this box there is no problem
(3) I tried to use the "Validation" tab and run a custom JavaScript.
PROBLEM: If you don't click on the box there is no validation so it is perfectly happy to leave the textbox blank if the user forgets to fill it in
OK, I am out of ideas... Anyone?
Since you are using Acrobat JavaScript I assume you use a viewer that supports and executes Acrobat JavaScript. In this situation you can set the document's WillSave action to a custom JavaScript action and perform validation here. I'm not sure if you can cancel the save operation but at least you can display an alert if the validation fails.
UPDATE: This script will loop through all the fields and display and alert if the field value is empty.
for ( var i = 0; i < this.numFields; i++) {
var fieldName = this.getNthFieldName(i);
var field = this.getField(fieldName);
if (field.value.length == 0)
{
field.setFocus()
app.alert("Field " + fieldName + " is required. Please enter a value.")
}
}
Put the script in document's Will Save action and it will run every time the user saves the form. In Acrobat you set this in Tools > JavaScript > Set Document Actions and select Document Will Save.
I have a Dojo form that does not contain a submit button. Instead, I added an onkeypress handler to calls a method when Enter is pressed. The problem I am having is that when I hit enter before blurring off the current field, the _process method thinks that field is empty.
Or in other words: type in field1. hit tab. type in field2. hit enter. field2 is blank unless i click off the field or shift-tab back.
Any ideas?
dojo.connect(dijit.byId("fkrform"),"onKeyPress",function(e) {
if (e.keyCode == dojo.keys.ENTER) {
_process();
}
and the method it calls:
function _process()
{
var field1 = dijit.byId("field1").value;
var field2 = dijit.byId("field2").value;
alert(username);
alert(password);
...do stuff...
}
The fields are of dojoType: dijit.form.TextBox, and the form is: dijit.form.Form
Use dijit.byId('field1').get('value') instead of directly try to access the property "value". In your example you saved the value in the variable field1 and field2 and in the alert you use the variable username and password could be the answer why you don't get anything. But you still should use the get method to get a property instead of directly access the property.
When you press "Enter" your form will submit. So you need to connect to the "onSubmit" event on the form, instead of onkeyPress or onKeyUp.
The first example i created prints the value of the input box on every key someone pressed in the console.
http://jsfiddle.net/a8FHg/
But what you really wanted was hooking into the submit. I modified the example. The new example connects to "onSubmit" and creates an alert box with the text of the user input.
http://jsfiddle.net/a8FHg/1/
For completness if jsfiddle doesn't work some day. You JavaScript should looks like this.
dojo.ready(function(){
var form = dijit.byId('form');
var box = dijit.byId('box');
var submit = function(event) {
dojo.stopEvent(event);
alert("User input was " + box.get('value'));
};
dojo.connect(form, 'onSubmit', submit);
});
Assuming your form in your HTML has the id form and your box have the id box.