Input Validation for PhoneTextBox in windows phone app 8 - windows-phone-8

i'm developing a windows phone application.in my application i want to make input validation for textbox.i'm using windows phone toolkit :PhoneTextBox
need to alert a Message when user fail to fill the textbox after click the submit button.is there any way to do that?
thanks!

In your Button_click event, add a condition,
if (!String.IsNullOrEmpty(PhoneTextBox.Text))
{
//your action here
}

In your Button's event handler make sure you have:
your eventhandler(){
if(string.IsNullOrWhiteSpace(this.textBox1.Text)) //here "tb" is the textbox name, in case of that give your textbox's name.
{
MessageBox.Show("TextBox is empty");
}
}
Or else try using String.IsNullOrWhiteSpace in order to check whether the string is empty.
if (String.IsNullOrWhiteSpace(Name)) //give the name of your textbox.Text
{
//Handled
}
Reference: String.IsNullOrWhiteSpace Method

On Button_click you have to check. Try following code.
if (!String.IsNullOrEmpty(YourTextBox.Text)) // it check it text box is null or empty
{
//your action here
}

Related

How to access the Card section input field value in Google App Script?

My card builder looks something like
function createSelectionCard(e) {
var builder = CardService.newCardBuilder();
builder.addSection(CardService.newCardSection()
.addWidget(CardService.newTextInput()
.setFieldName("text_input_form_input_key")
.setTitle("Enter Value")
.setValue('Test'))
....
return builder.build();
The documentation for Text Input says that setFieldName Sets the key that identifies this text input in the event object that is generated when there is a UI interaction but using e.text_input_form_input_key always results to a null value
function Embed(e) {
...
presentation.getSelection().getCurrentPage().insertImage(dataBlob)
.setDescription(e.text_input_form_input_key)
}
To retrieve the imputed value from a text input, you need e.formInputs.name:
For example, your add-on can locate the text a user has entered into a TextInput widget in the eventObject.commentEventObject.formInputs object.
To give you an idea, you can try with the following:
e.commonEventObject.formInputs.text_input_form_input_key.stringInputs.value[0]
For more details, you can refer to this documentation.
References:
Event objects

How to tell if SelectionInput checkbox is checked or not in callback?

How can you tell if a SelectionInput checkbox item is checked in a callback? I have the following:
section.addWidget(CardService.newSelectionInput()
.setType(CardService.SelectionInputType.CHECK_BOX)
.setFieldName("chkSaveAttachments")
.addItem("Save Attachments", "chkSaveAttachmentsValue", true));
I have a button on my card that triggers a callback. From the callback, all I can access is the value ("chkSaveAttachmentsValue") but I can't tell whether the box is checked or unchecked.
function saveCallback(e) {
Logger.log(e.formInput.chkSaveAttachments); //prints "chkSaveAttachmentsValue"
Logger.log(e.formInput.chkSaveAttachments.chkSaveAttachmentsValue) //undefined
Logger.log(e.formInput.chkSaveAttachments.chkSaveAttachmentsValue.selected) //undefined
}
As stated here, formInputs property would be helpful here.
For multi-valued widgets such as checkboxes, you can read each value from formInputs instead.
In formInputs, all the selected options will be there in an array(e.formInputs.chkSaveAttachments).
Hence, in your saveCallback function, you can check as
e.formInputs.chkSaveAttachments.indexOf('chkSaveAttachmentsValue') > -1
You can get the state of checkbox by looking at the formInput in the onChange callback.
CardService.newSelectionInput()
.setType(CardService.SelectionInputType.CHECK_BOX)
.setFieldName("chkSaveAttachments")
.addItem("Save Attachments", "chkSaveAttachmentsValue", true).setOnChangeAction(selectionAction)
var selectionAction = CardService.newAction().setFunctionName("selectionAction").setParameters({"obj": obj});
function selectionAction(e) {
//formInput value comes only when it is selected.
var selected = !!e.formInput.chkSaveAttachments;
// you can set and access paramters in the onchange action for further use.
if(selected) {
// cache the state using cacheservice
} else {
// cache the state using cacheservice
}
}

Only one type of action can execute?

I going to show my problem with an example:
I have a button. When clicked, it creates a mail draft based on the TextInputFields in the add-on.
I have a validate function, which can say if the fields filled right or not.
If I want to notify the user somehow about the wrong fields, I have to create a notify or rebuild the card with error information. These actions can be returned in a normal Action, but not with a composeAction (because composeAction has to return with builded draft), so I have to register a composeAction and a simple action to the button.
When I clicked this kind of button, only one of the action execute and the other do nothing.
Some code about how I tried to implement:
section.addWidget(CardService.newTextButton()
.setText('Validate and Create')
.setComposeAction(CardService.newAction().setFunction('doIt'), CardService.ComposedEmailType.STANDALONE_DRAFT)
.setOnClickAction(CardService.newAction().setFunction('notify')));
ActionFunctions:
function doIt(event){
validate the event['formInput'] object;
if(valid the formInput)
create andr return the draft;
else
return null;
}
function notify(event){
validate the event['formInput'] object;
if(valid the formInput)
return null;
else
return notify or rebuilded card with error info;
}
Mostly the simple action run, and the compose do nothing. If I place Logger.log() functions in the callback function, only one appears on api log.
Anyone have tried before validate and create draft at the same click?
How about this:
var action=CardService.newAction().setFunctionName('myFunction');
var validateCreateButton=CardService.newTextButton()
.setText('Validate & Create')
.setOnClickAction(action);
section.addWidget(validateCreateButton);
function myFunction(e) {
doit(e);
notify(e);
}

Toggle switch to pass unchecked value

I'm using a checkbox to create a toggle switch as shown in this tutorial
The switch lives in a form where questions can be added dynamically. On submission the form posts as array of each answer back to the page to be processed however as the off switch doesn't pass a value back to the form the answers get out of sync with the answers for the other text fields. Is there any way to set a value for the off switch, i.e. when a check box is left unchecked?
I've tried to use the following to set my off checkboxes to off however it just seems to animate all the switches to on on form submission, anyone any ideas as to what I'm doing wrong?
$('form').submit(function(e){
var b = $("input:checkbox:not(:checked)");
$(b).each(function () {
$(this).val(0); //Set whatever value you need for 'not checked'
$(this).attr("checked", true);
});
return true;
});
You probably want to use Javascript to set a value for each checkbox "switch" in one of two ways:
Option 1: in the html of the switch elements/checkboxes, set the value attribute to zero by default. Then add a javascript click handler for the toggle to check its current value and toggle to the opposite state/value.
Option 2: add Javascript to the form's submit handler (on submit) that checks for any switch elements which have no values and set them to zero before processing form.
Either way should pass a value at all times, and your form should be able to keep track of all input states.
This snippet did the trick, as Anson suggested this finds all the checkboxes and sets them to either on or off on form submission:
$('form').submit(function () {
$(this).find('input[type="checkbox"]').each( function () {
var checkbox = $(this);
if( checkbox.is(':checked')) {
checkbox.attr('value','1');
} else {
checkbox.after().append(checkbox.clone().attr({type:'hidden', value:0}));
checkbox.prop('disabled', true);
}
})
});

After Input goes Invalid in HTML5 set error message and prevent default error message from kendo in a grid

I stuck with the inline validation in the kendo grid.
I don't want to validate after losing focus. I want to validate immediately after typing. So I start using the HTML validator. It works pretty well but the problem is I cant answer these two questions:
which event set the input from valid to invalid.
which event displays the error message.
My Current work: https://dojo.telerik.com/OSONo/56
which event set the input from valid to invalid.
...
which event displays the error message.
Just run your kendoValidator with validator.validate();
The error messages are also set with validate().
Something like this should work:
$(document).on('input propertychange', function() {
validator.validate();
});
The warning seems to be hidden behind some elements, so you can also add the folowing errorTemplate to your kendoValidator:
errorTemplate: '<div class="k-widget k-tooltip k-tooltip-validation" style="margin: 0.5em; display: block;"><span class="k-icon k-i-warning"></span>#=message#<div class="k-callout k-callout-n"></div></div>'
And the whole solution:
https://dojo.telerik.com/OSONo/66
Solved my Problem on my Own. I will edit the post so you can see what i mean but first i just give the dojo projcet.
https://dojo.telerik.com/OSONo/64
my edit:
I am sorry for my previous anwser, i just want to give him my solution i mention in my comment.
In my solution i created an event listener, how listen to all input elements. When something has changed it, saves the current cursor position (its import for ie support) and after this it trigger my "change" event. The "change" event check if it is valid or invalid. If it is invalid the kendo validator shows imidently the error-message (not as default by a blur event).
var ValidierungCheckClass = (function () {
return {
AllDOMElements: function () {
$('body').on('input', function () {
var myActiveElement = $(':focus');
if ((myActiveElement) && (myActiveElement.context.activeElement.nodeName.toLowerCase() !== "body")) {
var myActiveDOMElement = myActiveElement[0],
start = myActiveDOMElement.selectionStart, //just for IE Support
end = myActiveDOMElement.selectionEnd; //just for IE Support
myActiveElement.trigger("change");
myActiveDOMElement.setSelectionRange(start, end); //just for IE Support
}
})
}
}
});
The change event is allready created from kendo so you dont have to write your own.
At least you have to call the method when creating the website.
<script>
ValidierungCheckClass().AllDOMElements();
</script>
This is my Solution to my problem.
best regards.