I have a form input field for a to-do list style app for iOS using cordova. I'd like the user to be able to enter characters such as: ! % & + However these caused the app to crash. My temporary fix was to restrict the key input on the form field using the .keypress function. However I'd like to find a way for users to be able to include these characters in their list items. (I also realized that adding a blank space as the only input causes the app to crash.)
I've see a lot of Q+As for validation that restricts the use of these characters but is it possible to be able to use them in a form input?
Thank you!
/* Form to make a new list item */
$('.formMain').submit(function () {
var key = Date.now();
var text = $('#todo').val();
var textTrim = text.replace(/ /g, '').toLowerCase();
var checked = false;
var quantity = $('#quantity').val();
// if the inputs are blank
if (text.length == 0) {
return false;
}
// if item already on list
else if ($('.list #' + textTrim).length) {
alert(text + " already on list!");
}
// if the input box is not empty run the template function
else if ((text.length > 0) === true) {
var html = template(text, textTrim, key, checked, quantity);
$('.list').append(html);
itemListArray.push({ key: key, text: text, textTrim:textTrim, checked: checked, quantity: quantity});
// Save the item list array
if (window.localStorage) {
window.localStorage.setItem('itemListArray', JSON.stringify(itemListArray));
}
$('#todo').val("");
$('#quantity').val("");
}
return false;