I try to trigger a Seyren alert if the value received is null, but can't find a way to do so.
I have read several answers, like here and also here which says that it should be possible with the Allow no data checkbox.
However, what should I put into the field Warn level and Error level, since those fields are useless though mandatory?
Thanks for your help!
The way I've done this before is to use the transformNull function to switch a null value with something else which you can then alert on.
For example, if I always expect my values to be 0 or greater and null would signal a problem I'd use a target of transformNull(my.target.string,-1). I can then use a warn value of -0.5 and error value of -1 to trigger an alert when there's a null value.
The value you choose to switch null with will vary depending on the data you've got but hopefully you should be able to find something.
Related
I have an Access form bound to linked view called vwBudgetEntries from SQL Server. The form contains a combo box bound to a field called SubcodeID which is short text and has the following properties:
Meanwhile, the row source of the combo box pulls a unique list of all subcode id's, including one where it's an empty string. For some reason, however, selecting this option throws the following error:
For the life of me, I can't figure out why. The value should be empty string, not null. If I change the combo box to a textbox and enter "", the update is accepted without any errors.
I've done what research I can and, so far, I've only found 2 workarounds:
Change the field properties to allow null, then replace null values with an empty string after the control updates.
Trap the error in the form_error event, undo the update and supply the value using VBA.
Neither workaround is ideal. Can someone explain why this error is occurring in the first place and what I might do to fix it?
Storing empty strings should be avoided for anything else than very special cases, or you will meet issues like this. So:
Set Required to No
Set Allow Zero Length to No
Store Null for the choice of unknown value for SubcodeID
I integrate typescript into my React application. I keep the initial state of the input element as an empty string. But the number value must be entered in this input. Typescript naturally says that you cannot assign a number value to the string value. How can I solve this problem, what is the conventional way of doing this? By the way, I didn't share the code because I thought it wasn't necessary to share it.
As a rule of thumb, initialize those values to be null. By default, if the strictNullChecks is set to false Typescript allows you to set an initial value of null.
So this will not error: val: number = null and also is more readable in terms of your code intention.
With that being said, even if strictNullChecks is true in your settings, you could always assign an initial null value like with the non-null assertion opreator !, which tells Typescript that its ok the initial value is null and you will handle the assignment later yourself:
val: number = null!;
EDIT:
As suggested in the comments, you can also use union types like this: val: number | string = ''
See the example here.
Using the $validators pipeline, I am trying to check that a field contains the same value as another field.
Each input in this example is associated with the other, such that the expected result is as follows:
Enter a value in input#1
Enter same value in input#2
Both fields should now be valid
Alter the value in input#1
input#1 should be invalid (or input#2 or both)
Initially, I did this using a $watch on both the current model and the target to be equal to, so only one of the two fields needed to use the directive. However, with the introduction of the $validators pipeline, this method stopped working unexpectedly (maybe a bug).
Anyhow, as you can see, when the second input is altered, the value is receives for the associated input is undefined.
Solution
I solved this by the following:
JSFiddle
As Nikos said, the two instances were cancelling each other out, so this was fixed by the following code:
$scope.$watch('passwordWatch', function(pass) {
$control.$validate();
});
So now, when the target input changes, the current input revalidates. When the current input changes, it validates automatically (as usual).
One problem is that when a validator fails (returns false), then the underlying model value is set to undefined. So:
You type something in the password, say "aaa"; this is NOT the same as passwordConfirm, so the validator returns false and the model gets the undefined value
You type the same value in passwordConfirm; but from above the value of the password is undefined and undefined !== "aaa", so the passwordConfirm validator returns false too.
And so on...
I'd like to be able to run a query like: MyModel.query(MyModel.some_property == None) and get results. I know that if I don't put a default=<some default> in a property, I won't be able to query for it, but if I set default=None will it index it?
Similarly, does setting values to None cause properties to be indexed in ndb.Model? What if you pass some_keyword_arg=None to the constructor?
I know that doing something like: ndb.StringProperty(default='') means you can query on it, just not clear on the semantics of using None.
Explicitly setting a property to None is defining a value, and yes defaults work and the property will be indexed. This assumes None is a valid value for a particular property type.
Some issues will arise, as you pointed out, often you use None as a sentinal value, so how do you tell between no Value provided and an explicit None?
I know that CoerceValueCallback is used to correct a value and that ValidateValueCallback will return true or false. But my question is why we need ValidatevalueCallback? We can simply use CoerceValueCallback to validate (using if condition) and correct the value. Can you give some practical example of when to use coercion vs. validation?
Here are the rules I follow for when to use coercion vs. validation.
Use CoerceValueCallback If...
You can safely correct a value to be valid without needing to throw an error.
Your property depends on one or more other dependency properties.
You need to provide instance-level validation as opposed to class-level validation.
You allow others to override your validation logic.
Use ValidateValueCallback If...
You cannot correct a value to be valid.
You must throw an error if an invalid value is provided.
You do not want others to override your validation logic.
So, it primarily depends on whether or not your property depends on other dependency properties or if you want others to be able to override your validation logic.
Since the ValidateValueCallback is not part of the PropertyMetadata, inheritors cannot modify the callback through the DependencyProperty.OverrideMetadata function.
Also, since the ValidateValueCallback does not provide your DependencyObject as a parameter, you cannot perform advanced validation that depends on other dependency properties.
Example 1
Suppose you have Minimum, Maximum, & Value properties. When any of these change, a CoerceValueCallback shoud be used to ensure the other properties are consistent.That is, Minmum <= Value <= Maximum.
However, assuming these values are doubles, then there are some values that would never make sense, namely Double.NaN, Double.PositiveInfinity, and Double.NegativeInfinity. Therefore, a ValidateValueCallback should be used to verify that the double values are normal, numeric values.
In fact, this is exactly how RangeBase works!
Example 2
Suppose you have a RegexTextBox control which takes a string containing a regular expression (call it RegexString). If a bad regular expression is provided, then what should be used instead? It might make sense to coerce it to be a null/empty value, rendering it useless; however, I suggest that this property be validated with a ValidateValueCallback. This is because any error is now thrown at compile-time when designing via the WPF designer.
For this property, there shouldn't be a CoerceValueCallback at all.
There is a whole lot of information describing how to use these callbacks.
I'd suggest taking a look at the MSDN article, Dependency Property Callbacks and Validation, for more in-depth knowledge.
Value coercion is basically to change the value, if the the new value is not as system expected. A best example is Slider control. A Slider has both Minimum and Maximum properties. Clearly, it would be a problem if the Maximum value were allowed to fall below the Minimum value. Value coercion is used to prevent this invalid state from occuring.
Validate value, is something that system will only check whether the given input is valid or not. It will throw Argument Exception if value is invalid (if we returned false for such value). For example, we have Age property, and it should be in range of 0 to 120. In case the new value is 500, the system may warn the user instead coercing it to some hardcoded value.
Any way both callbacks are optional and can be used based on the requirement.