Password matching in AngularJS using the $validators pipeline produces unexpected results - angularjs

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...

Related

Access Combobox is replacing empty string with null, then throwing error 3162

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

How to stop an SSRS report with optional parameters from rendering

I have a report that has multiple parameters. The user will filter the data by inputting a value in to one of them.
All the parameters are created by the query and have the following design (fieldname = #param OR #param IS NULL)
In the parameter properties window, they have been changed to allow NULL values. The issue with this, is that the report renders initially with all data returned, as each parameter has the NULL checkbox ticked as default. From there you can input a value to one parameter and the report will filter as desired.
I would prefer the report not to render until one value has been given to one of the parameters. I am aware I can use a default value for one of the parameters, which would return no data, but this isn't ideal, as you still get the rendering of the report.
Is there a way to run the report but not render until a value is passed to one parameter?
-Write a custom code that checks the parameter value
Function GetReportCode(ParamVal AS String) As integer
Return IIf(ParamVal Is Nothing, 1/0, 0)
End Function
-If your parameter value is NULL then it will return an arithmetic overflow error
-Create a new variable with help of the following experision.
code.GetReportCode(Parameters!ReportParameter1.Value)
If the parameters takes NULL values it will return an error.

How to access to a Combo box value in Item Line on NetSuite?

In NETSUITE
is there any way to access to a value inside of a combo-box at the item line level?
I need to access to a value after inserting an item but all functions get me null value.
I have tried
nlapiGetCurrentLineItemValue
and
nlapiGetFieldValue
Both functions are getting me null values.
Thanks,
Pablo.
In general (for user event and client script) below code should work
nlapiGetLineItemValue(LINE_ITEM_TYPE, YOUR_FIELD_ID, LINE_NUMBER);
eg on SO to get the line item Id:
nlapiGetLineItemValue('item', 'item', 1);
PS: Syntax is independent of data type or field type
If you mean combo box as a mulitselect, and if you're trying to access via User Event Script, use:
nlapiGetLineItemValues(type, fldname, linenum);
Note the 's' in nlapiGetLineItemValues
If its just a standard field, nlapiGetLineItemValue(type, fldname, linenum) should work.
Which call to use depends on what event you are capturing.
For instance if you are trying to access the value in a post sourcing, field changed or line validate event of a client script you would use nlapiGetCurrentLineItemValue('item', 'fieldname');

What does this error actually mean?

So I have seen this error show up, just sometimes, but it is not helpful in describing the actual error which has occured. Nor does it give any clues as to what might cause it to display.
Cannot use modParams with indexes that do not exist.
Can anyone explain more verbosly what this error means, what it relates to (such as a behaviour, component, controller, etc), the most common causes and how to fix it?
To kickstart the investigation, you can find the error here.
https://github.com/cakephp/cakephp/blob/master/lib/Cake/Utility/ObjectCollection.php#L128
Layman's Terms
CakePHP is being told to apply an array of parameters to a collection of objects, such that each particular object can modify the parameters sent on to the next object. There is an error in how CakePHP is being told to do this.
In Depth
Generically, this rises from the CakePHP event publication mechanism. Somewhere in your code is an instance of ObjectCollection, which is being triggered with certain parameters. That is, a method is being called on every object in that collection.
Each callback method is given parameters. Originally the parameters are passed into trigger(). In normal cases (where modParams is false), every callback gets the same parameters. But when modParams is not strictly false, the result of each callback overwrites the parameter indicated by modParams.
So if there are two objects in the collection, modParams is 1, and the params[1] is 'a' initially, then the callback is given the first object with params[1] == a. That callback returns 'b', so when the next callback is called, the second object gets params[1] == b.
The exception raises when the modParams value given does not exist in the originally given params. Eg, if modParams is 2 and params is array (0 => 'a', 1 => 'b'), you'll get this exception.
In your case
Specifically, debugging this has to be done at a low-level because it's a method on a generic class. The backtrace from the Exception should get you bubbled up to a trigger() call on a particular concrete class. That call is being given non-false modParams and a params that doesn't have the given modParams. It could be a code bug in a concrete class extending ObjectCollection, or it could simply be a generic message arising from a method not being given expected arguments.
Have you tried reading the documentation?
/*
* - `modParams` Allows each object the callback gets called on to modify the parameters to the next object.
* Setting modParams to an integer value will allow you to modify the parameter with that index.
* Any non-null value will modify the parameter index indicated.
* Defaults to false.
*/
You did not paste any code, so I guess your 3rd arg of the method contains something wrong.

Difference between CoreceValueCallback and ValidateValueCallback?

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.

Resources