How to set $invalid true to a field in form through a directive in AngularJS - angularjs-directive

Can anyone please help me to set either $invalid to true or $valid to false through a directive.
When I tried to console.log(ctrl) I got an array named FD having names of the field as well as form name...
ctrl.$name gave me form name but ctrl.fieldname gave me undefined.
But the fieldname is present in ctrl. How can I move forward
Thanks in advance

The only way I could solve this was by manually enabling or disabling ng-required.

Related

concatenate variables in angular property element

I comment, and looked here and I can not find the solution, my problem is the following:
in my html template in angular, I need to pass a series of data to the metadata property of a button, I can't get the correct way to successfully concatenate the variable that contains the value.
this should be the html element:
<mati-button clientId="clientId" flowId="flowId" color="green"metadata='{"user_id":"1234778","email":"som#som.com"}'/>
I tried several ways but I can't insert the respective values....
example:
<mati-button metadata='{"userID": "{{user.id}}" }'></mati-button>
unsuccessfully...
Assuming mati-button is an Angular component with metadata as Input(), you are probably looking for
<mati-button
[clientId]="clientId"
[flowId]="flowId"
[color]="green"
[metadata]="{ userId: '1234778', email: 'som#som.com'}"
></mati-button>
See the guide on property binding to learn more:
To bind to an element's property, enclose it in square brackets, [], which identifies the property as a target property. [...] The brackets, [], cause Angular to evaluate the right-hand side of the assignment as a dynamic expression. Without the brackets, Angular treats the right-hand side as a string literal and sets the property to that static value.
By "dynamic expression" they mean JS-expressions, i.e., a public variable available through the component's TypeScript, a boolean expression, an array, or, like in your case, a JS-object that you can construct inline.
You can try doing this
<mati-button metadata="{'userID': user.id }"></mati-button>
metadata='{" userID ": {{user.id}}}'
in the end I got it. Apparently I don't know why, but the third-party script hides that parameter and it couldn't be debugged in the console, but it does receive them without any problem! Thanks everyone for your help!

Greyout/disable a field with ng-model

I have 3 radio buttons with ng-model - client.ssoApiClientAuth and ids - apiClientAuthMeth0, apiClientAuthMeth1, apiClientAuthMeth2
I have a password field with ng-model - client.newPassword and id - apiClientSecret.
I need to greyout/disable password field when apiClientAuthMeth1 is selected.
I am not familiar with these Angular techniques. Could anyone tell me the solution?
If you have the apiClientAuthMethN as property in your component you can disable fields like this:
<div [disabled]="apiClientAuthMeth1"></div>
To disable password property use [disabled]="apiClientAuthMeth".
apiClientAuthMeth will be a boolean variable.
When apiClientAuthMeth1 is selected call a function to typescript and set apiClientAuthMeth to true. This will disable your field and if another radiobutton is selected then make this variable false and it will enable your password field

using checkboxes in Laravel's Form::model

I'm having trouble with Laravel's Form::model() construct. I was able to populate it with my model data but the checkboxes aren't being checked. The values are being set to 1 or 0 (courtesy of Eloquent calling a "boolean" a "tinyint" in MySQL), but I can't see how to use the Form::model() approach and set that checked attribute if the value coming is an integer and not a boolean (hence why I think Form Model Binding for checkboxes isn't working).
I'm specifying this in my view:
{{ Form::checkbox('hasDiscount') }}
And the form builder is returning this:
<input name="hasDiscount" type="checkbox" value="1" id="hasDiscount">
I think it's not really related to data-value. The value could be 'true' and the checked attribute could be false as well.
If you want to display checkbox with checked attribute, you can try my wait (it's not the best, I admit):
Form::model($model)
Form::checkbox('name', null, $model->value)
Form::close()
The third parameter could be convert to false if the value of model is null or 0 and the checkbox is not checked. otherwise, it's checked.
If you have another idea, please share it.

to validate checkbox input for table using multiple rows

i using js to add multiple row in a particular table, but when submit the form all check box having the same value, so how can i validate this checkbox using js before submit so change value to if unchecked, i trying on that but got no solution, does any one this before,
thanks in advance
What are your checkboxes called? Do they all have the same name? You have two options. One is giving each checkbox an unique name, the other is giving your checkbox a name like checkboxes[]. The [] lets all the values be entered into an array so they don't overwrite eachother.
If you mean something else, you have to state more clear what you want, because it's a bit incomprehensible right now.
finally i found solution for my problem, thanks 'vindia' for the clue, i add checkbox with array, sol as below
in html
`<input id="abc[]" name="abc[]" type="checkbox" value="1">`
in js
for(var i=0;i<chkDefaultLength;i++){
if(!document.neworupdateevent["chkDefault[]"][i].checked){
document.neworupdateevent["chkDefault[]"][i].value=0;
}
}

Html.DropDownList select value not being set by Model

I have a drop down list like so:
<%= Html.DropDownList("SoldTo", Model.SellDealerList, "Select a Dealer")%>
I'm populating the list in my Controller with the following code:
SellDealerList = new SelectList(repository.GetDealerList(), "id", "name", vehicle.SoldTo);
When I debug through the code the selected value on the SellDealerList has a value that is being set but the HTML source shows no selected value in the list.
I'm baffled as to what I'm doing wrong, but being new to MVC I'm sure it is probably something very simple. The biggest difference from all the other questions and answers I've seen is that I'm not using the ViewData.
Thanks!
Check my answer to this question, maybe it helps.
Perhaps you have a property "SoldTo" in your model, ViewData or ModelState. The DropDown tries to override the selected value if some of these objects has a property or key with the same name as your field. Is kind of crazy if you don't know how it works internally because you see the selected property set to true on the right item of the SelectList and yet no option of the select is selected.