ng-hide not working once the input field is clicked - angularjs

<md-radio-group ng-model="orderDetails.productType" layout="row">
<md-radio-button value="paper" class="md-primary"><h4>Paper</h4></md-radio-button>
<md-radio-button value="nonPaper"><h4>nonPaper</h4></md-radio-button>
</md-radio-group>
<md-input-container class="md-block" ng-hide="orderDetails.productType === 'paper'" >
<label>Non-Paper Type</label>
<input type="text" name="nonPaperType" ng-required="orderDetails.productType === 'nonPaper'" ng-model="orderDetails.nonPaperType"/>
</md-input-container>
I am trying to hide the input container, however, first it works fine, but after clicking on the input it won't hide.

Here you go - CodePen
Markup
<div ng-controller="AppCtrl" ng-cloak="" ng-app="MyApp" layout-padding>
<md-radio-group ng-model="orderDetails.productType" layout="row">
<md-radio-button value="paper" class="md-primary">Paper</md-radio-button>
<md-radio-button value="nonPaper">Non Paper</md-radio-button>
</md-radio-group>
<md-input-container class="md-block" ng-hide="orderDetails.productType === 'paper'" >
<label>Non-Paper Type</label>
<input type="text" name="nonPaperType" ng-required="orderDetails.productType === 'nonPaper'" ng-model="orderDetails.nonPaperType"/>
</md-input-container>
</div>

Actually this is an Angular material Issue
https://github.com/angular/material/issues/6536
But if you remove the ng-required it should work.
May be this fiddle helps you :
`https://codepen.io/anon/pen/BLjmZP`

Related

How to make a radio input in a dropdown

In angularjs and materialjs.
a select is in a dropdown, a radio is not in a dropdown
Codepen
How to make radio input also in dropdown? do I have to code it entirely by myself? or is there some hidden properties?
<div class="radioButtondemoBasicUsage" ng-app="MyApp">
<form ng-controller="AppCtrl" ng-cloak="">
<p>Selected Value: <span class="radioValue">{{ data.group1 }}</span> </p>
<md-radio-group ng-model="data.group1">
<md-radio-button value="Apple" class="md-primary">Apple</md-radio-button>
<md-radio-button value="Banana"> Banana </md-radio-button>
<md-radio-button value="Mango">Mango</md-radio-button>
</md-radio-group>
<hr>
<div>
<span>What is your favorite weapon?</span>
<md-select ng-model="weapon" placeholder="Weapon" class="md-no-underline">
<md-option value="axe">Axe</md-option>
<md-option value="sword">Sword</md-option>
<md-option value="wand">Wand</md-option>
<md-option value="pen">Pen?</md-option>
</md-select>
</div>
</form>
</div>

Form in Angular Dialog - Get form data after dialog close

I created a webpage with Angularjs and Laravel. It's an event page.
In my admin-panel I can manage all events.
When I click at "Bearbeiten" a new window appears.
At the bottom I can add/remove different attractions. When I submit the form, I want save the new data in the database, but I don't know how I can get the data from the formula. I tried different thinks and yes I used google.
When I click at "Bearbeiten" following code will be executed:
<md-dialog-content style="padding: 20px;">
<div layout-gt-sm="row">
<md-input-container class="md-block"flex-gt-xs>
<label>Name (Bsp: Schützenfest, Kirmes, Sommerdom)</label>
<input value="{{ $data['event']->name }}" name="event_name">
</md-input-container>
<md-input-container class="md-block">
<label>Stadt (Bsp: Hannover, München, Köln)</label>
<input value="{{ $data['event']->city }}" name="event_city">
</md-input-container>
</div>
<div layout-gt-sm="row">
<md-input-container class="md-block" style="margin: 0" flex-gt-xs>
<label>Straße</label>
<input value="{{$data['event']->street }}" name="event_street">
</md-input-container>
<md-input-container class="md-block" style="margin: 0" flex-gt-xs>
<label>Postleitzahl</label>
<input value="{{ $data['event']->zip->id }}" name="event_zip">
</md-input-container>
<md-input-container class="md-block" style="margin: 0">
<label>Webseite</label>
<input value="{{ $data['event']->website }}" name="event_website">
</md-input-container>
</div>
<div layout-gt-sm="row">
<md-input-container class="md-block" style="margin: 0" flex-gt-xs>
<label>Start (YYYY-MM-DD)</label>
<input value="{{$data['event']->start }}" name="event_start">
</md-input-container>
<md-input-container class="md-block" style="margin: 0" flex-gt-xs>
<label>Letzter Spieltag (YYYY-MM-DD)</label>
<input value="{{$data['event']->end }}" name="event_end">
</md-input-container>
</div>
<md-chips ng-model="mdDialogData[0]" name="event_attractions" readonly="false"
md-removable="true" md-max-chips="100" placeholder="Attraktionen">
<md-autocomplete
md-selected-item="mdDialogData[1].selectedItem"
md-search-text="mdDialogData[1].searchText"
md-items="item in mdDialogData[1].querySearch(mdDialogData[1].searchText)"
md-item-text="item"
placeholder="Attraktion suchen">
<span md-highlight-text="mdDialogData[1].searchText" style="width: 280px;">#{{ item }}</span>
</md-autocomplete>
<md-chip-template>
<strong style="margin-right: 15px;">#{{$chip}}</strong>
</md-chip-template>
</md-chips>
</md-dialog-content>
<md-dialog-actions layout="row">
<span flex></span>
<md-button ng-click="answer([#{{ mdDialogData[0] }}, '1', '2'])">
Änderungen speichern
</md-button>
<md-button ng-click="answer('useful')">
Abbrechen
</md-button>
</md-dialog-actions>
I am not really good with angular. Maybe are here some experts!
Since the data is already populating on the popup, I will assume you have correctly passed the data array to the function/module responsible for the popup.
Now, all you need is to update the array containing variable data fields that you are modifying. You will need to remove the data you chose to remove from the array, or keep adding if you are adding new values. You will then need to pass updated array as you click on ABBRECHEN and need to update the new values in the DB. The data removed from the array will create empty spaces in the array, you can either remove it on the Angular or Backend, or simply put the logic to skip if particular index is null/undefined.

Angularjs Material Datepicker is not working when i am trying to use it with ng-switch

I am trying to use angular material datepicker with ng-switch, which i have given to a radio buttons based on the radio option date picker should load. But it is not working as expected.
This is how my code looks like.
Radio buttons
<div class = "row radio">
<md-radio-group ng-model="data.group1">
<md-radio-button class="md-primary fix-width" ng-model="myVar" value="OneWay">One-way</md-radio-button>
<md-radio-button class="md-primary fix-width" ng-model="myVar" value="RoundTrip">Round Trip </md-radio-button>
<md-radio-button class="md-primary fix-width" ng-model="myVar" value="MultyWay">Multi-Way + Hotal</md-radio-button>
</md-radio-group>
</div>
Date picker
<div class = "row Date" ng-switch="myVar">
<div class = "col-lg-1"></div>
<div class = "col-lg-6" ng-switch-default>
<md-input-container>
<label>Depart on</label>
<md-datepicker ng-model="user.submissionDate"></md-datepicker>
</md-input-container>
</div>
<div class = "col-lg-10" ng-switch-when="RoundTrip">
<md-input-container>
<label>Depart on</label>
<md-datepicker ng-model="user.submissionDate"></md-datepicker>
</md-input-container>
<md-input-container>
<label>Return on</label>
<md-datepicker ng-model="user.submissionReturnDate"></md-datepicker>
</md-input-container>
</div>
</div>
when i click on one way it should show the single datepicker and if i select Round trip it should show the roundtrip block.
Hope there is no js required for this functionality?
May i know what is wrong hear?
ng-model="myVar" needs to be on the md-radio-group element - CodePen
Also, if you look in the console there is an error regarding putting md-datepicker within an md-input-container element.
Markup
<div ng-controller="AppCtrl" ng-cloak="" ng-app="MyApp">
<div>
<md-radio-group ng-model="myVar">
<md-radio-button class="md-primary fix-width" value="OneWay">One-way</md-radio-button>
<md-radio-button class="md-primary fix-width" value="RoundTrip">Round Trip </md-radio-button>
<md-radio-button class="md-primary fix-width" value="MultyWay">Multi-Way + Hotal</md-radio-button>
</md-radio-group>
</div>
<div ng-switch="myVar">
<div ng-switch-default>
<div layout="column">
<label>Depart on</label>
<md-datepicker ng-model="user.submissionDate"></md-datepicker>
</div>
</div>
<div ng-switch-when="RoundTrip">
<div layout="column">
<label>Round trip</label>
<md-datepicker ng-model="user.submissionDate"></md-datepicker>
</div>
</div>
<div ng-switch-when="MultyWay">
<div layout="column">
<label>Multi way</label>
<md-datepicker ng-model="user.submissionReturnDate"></md-datepicker>
</div>
</div>
</div>
</div>

Form validation not working in mdDialog

I have this simple working form, but when I put this in a $mdDialog it doesn't disable the submit button anymore... it basically ignores the networktypeForm.$invalid Is this common or is there a fix for this?
<form name="networktypeForm" ng-submit="add()" novalidate role="form">
<div class="md-dialog-content">
<md-input-container md-no-float flex>
<label>Element type</label>
<input flex ng-model="type" name="networktype" type="text" required="">
<div ng-messages="networktypeForm.networktype.$error">
<div ng-message="required">This is required</div>
</div>
</md-input-container>
</div>
<md-dialog-actions layout="row">
<md-button type="submit" class="md-primary md-raised" ng-disabled="networktypeForm.$invalid">
Add
</md-button>
</md-dialog-actions>
</form>
your requireds should be like this required not required="" or required="required"
For those still looking at this, I had a similar issue and mine was solved by removing the "novalidate" attribute.

Angular material layout isn't consistent

I'm having problem with designing simple form.
<div layout="column" ng-cloak>
<md-content class="md-padding">
<form name="search">
<md-input-container>
<label>From where?</label>
<input name="from" ng-model="from" required>
</md-input-container>
<md-input-container>
<label>To where?</label>
<input name="to" ng-model="to" required>
</md-input-container>
<md-datepicker ng-model="date" md-placeholder="When?" ng-required="true" required></md-datepicker>
<md-input-container>
<md-button class="md-raised md-primary">Search</md-button>
</md-input-container>
</form>
</md-content>
</div>
This is how it looks, I don't know am I doing something wrong? I'm new to this framework. I want all inputs to be aligned to same base line, and I wan't to add icons in front of text inputs.
There are known issues with input alignment at the moment. You would have to tweak some margins if you want to align it yourself.
https://github.com/angular/material/issues/6636
https://github.com/angular/material/issues/6219
You can get icons in the input containers by specifying a <md-icon>.
<md-input-container class="md-icon-float md-block">
<label>Name</label>
<md-icon md-svg-src="img/icons/ic_person_24px.svg" class="name"></md-icon>
<input ng-model="user.name" type="text">
</md-input-container>
Check the documentation for more input examples.
Your structure has only one md-content under the layout="column". To stack the md-input-container and md-datepicker items you would need to add layout="column" to the form tag <form name="search" layout="column">which is the tag that is the parent to the tags your want to stack in a column.
<div layout="column" ng-cloak>
<md-content class="md-padding">
<form name="search" layout="column">
<md-input-container>
<label>From where?</label>
<input name="from" ng-model="from" required>
</md-input-container>
<md-input-container>
<label>To where?</label>
<input name="to" ng-model="to" required>
</md-input-container>
<md-datepicker ng-model="date" md-placeholder="When?" ng-required="true" required></md-datepicker>
<md-input-container>
<md-button class="md-raised md-primary">Search</md-button>
</md-input-container>
</form>
</md-content>
</div>

Resources