I know I can make Angular validate inputs against regex, so I can allow/deny certain values. But is there a way to validate an input value against a custom function?
For example, say that the input value is pushed in an array and I want to check if the value of the input is already in the array.
Also, I want to be able to mark the input as invalid or required, the same way Angular would do it if I was using plain regex.
Related
I'm trying to get the field values and field meta data ie., field properties,
Using the following script I'm able to find the field type and field properties. Now im trying to check if there is any null value in the a particular field, so that I can replace the field value with the default values based on the field type.
How can I read the field values without using the input fields ie.,hard coding (ie., to use some inbuilt functions as of how we get the meta data)following is the snip of code that i used to get the field properties
I'm pretty inexperienced with JavaScript, but I'm trying to do something that seems like it should be simple. I have a text input field (FieldA) in a FormAssembly form. I have another text input field that’s a calculated field (FieldB), and I want FieldB to return one value if FieldA is empty and a different value if FieldA is not empty. The formula I’m using in “Enter the calculation” looks like this:
if(FieldA==""){"empty"}else{"not empty");
When I go to the form, the result is “error” in FieldB, and adding a value to FieldA has no effect. When I do it in Preview mode, I get the additional message “There was an error computing this field.” FieldA here is tfa_40, but it seems to make no difference whether I use tfa_40 or define it as a variable and use the variable name. It also doesn’t seem to matter whether I use double quotes, null, or 0. Am I taking the wrong approach here? Is this even possible?
I'm looking to have both value and placeholder at an input field... the value would be more like twitter's #mention... it's the text the user need to have to start the input, and the placeholder gives hint to what user needs to type.
It seems like this can't be accomplished with only html
But is there anyway to make this possible in javascript or other means?
Use either two input fields (one with value and one with hint) or just use a label to tell the user the string always starts with #mention (or something else).
In the code to handle the input you then append both strings.
When using the .each function with JQuery like below is there anyway to automatically group the results by type to save some time;
$(selector).each(function () {
//do stuff here for each found
});
The above will obviously go through each found element one by one but with the logic within my code I'm just detecting what field type the field is and I would action each field type to do the same thing. I'm just trying to save doing all the logic for the same field type over and over again.
To detail a little more, I have a value and it needs to go into may different fields types. Simple text fields are fine as they're just insert in using .val() but for other default and custom fields that I have such as picklists and multi-select boxes I need to do some logic around the value for these fields so the appropriate values are set, but not all these type fields don't exist so don't want to do the necessary logic beforehand if those fields don't actually exist. So if I had 50 picklist fields I would obviously only want to do that logic once and set the values for all picklist fields to this value(s) that the logic had set. I just thought they're might be a simple method of JQuery that I'm missing here?!
You can do some manual testing and run your code a different way
var all = $(selector),
text = all.filter('[type="text"]'),
select = all.filter('select');
text.val(someValue);
if (select.length){ // select elements exist
// do logic and apply to all
select.val(selectSpecificValue);
}
I am on CakePHP 1.2 at the office and, following my last question, I would like to send the array key of the selected option in a SELECT input instead of sending its actual value. I have tried a few things with the Model::beforeSave() function, without success.
I am aware that the data posted by CakePHP does not include the whole array, but only the selected value.
Here is what the function looks like at the moment:
function beforeSave(){
$this->Post->set('category_id', = array_keys($this->data['Annonce']['category_id']);
# debug($this->data);
}
Would there be a way to store the array keys into an hidden input and changing this input value depending on the user's selected item in the SELECT input, and to also omit sending the user's input but still send the hidden value?
$categories = Set::combine($categories,'{n}.categories.id', '{n}.categories.nom');
This did it for me... CakePHP assigns the array_keys() values automatically to the value field of the input.