Why the form disappear using ngFor directive - html

When I am using ngFor directive in the form tag, the entire form will disappear. Can anyone guide me on how I can fix this issue?
<form #myforms="ngForm" *ngFor="let i of editaddress">
<div class="p-3 p-lg-5 border">
<div class="form-group row">
<div class="col-md-12">
<label for="c_fname" class="text-black">Save this address as<span class="text-danger">*</span></label>
<input type="text" class="form-control c_fname" value="{{i.title}}" name="title" [(ngModel)]="location.title" #title=ngModel>
</div>
<div class="col-md-6">
<label for="c_fname" class="text-black">First Name<span class="text-danger">*</span></label>
<input type="text" class="form-control c_fname" value="{{i.first_name}}" name="fname" [(ngModel)]="location.first_name" #fname=ngModel>
</div>
<div class="col-md-6">
<label for="c_lname" class="text-black">Last Name<span class="text-danger">*</span></label>
<input type="text" class="form-control c_lname" value="{{i.last_name}}" name="lname" [(ngModel)]="location.last_name" #lname=ngModel>
</div>
</div>
</div>
<div class="col-lg-12">
<input type="submit" class="btn btn-primary btn-lg btn-block" value="Save" (click)="saveAddress(location)">
</div>
</div>
</div>

Since you did not show any part of the underlying controller, the only thing I can do is inform you that the property editaddress would be an empty array. Therefore it would not render anything.
If it flashes and disappears, it means that through your life cycle the array may have content, but at some point the array is set to [] which updates the the markup accordingly.

Related

ng-disabled not working for multiple inputs

I have the following html form
<form name="enviarAutorizacao" id="enviarAutorizacao" novalidate>
<label class="form-label-gray">autorization</label>
<input class="form-control col-sm-6" ng-model="current.autorizacao" id="autorizacao" ui-mask="" maxlength="20" required>
<div class="form-group col-sm-8">
<label class="form-label-gray"> Value </label>
<div class="form-group col-sm-2 form-label-gray">
<label>$</label>
</div>
<div class="form-group col-sm-9">
<input class="form-control" maxlength="16" ng-model="current.valor" required id="valor">
</div>
</div>
<div class="form-group col-sm-12">
<button class="btn btn-default" ng-disabled="enviarAutorizacao.$invalid || enviarAutorizacao.$pristine" id="submit-representante-estabelecimento" ng-click="validateAssociate()">click me</button>
</div>
</form>
I am trying to enable the submit button, only when the 2 inputs are filled, but it is enabling right when I type on the first input (autorizacao).
I tried few alternatives, like change "ng-disabled="enviarAutorizacao.$invalid" to "ng-disabled="!enviarAutorizacao.$valid", but didnt works.
What is wrong with this html ?
If you use enviarAutorizacao.autorizacao.$invalid you will know if the "autorizacao" input is Invalid.
[form id].[input name].[$valid or $invalid or $dirty...]
So your code should be like this:
I changed the input's name and submit's ng-disabled
<form name="enviarAutorizacao" id="enviarAutorizacao" novalidate>
<label class="form-label-gray">autorization</label>
<input class="form-control col-sm-6" ng-model="current.autorizacao" id="autorizacao" ui-mask="" maxlength="20" name="autorizacao" required>
<div class="form-group col-sm-8">
<label class="form-label-gray"> Value </label>
<div class="form-group col-sm-2 form-label-gray">
<label>$</label>
</div>
<div class="form-group col-sm-9">
<input class="form-control" maxlength="16" ng-model="current.valor" required id="valor" name="valor">
</div>
</div>
<div class="form-group col-sm-12">
<button class="btn btn-default" ng-disabled="enviarAutorizacao.autorizacao.$invalid || enviarAutorizacao.valor.$invalid" id="submit-representante-estabelecimento" ng-click="validateAssociate()">click me</button>
</div>
</form>
Try using the ids of the actual inputs individually as the arguments to ng-disabled.
Alternatively you could check the validity of current.autorizacao and current.valor and use those.

HTML Form Post handling

I have a form as detailed below. It uses a post method to send data to getUsername.php. This file echoes some JSON results from mysql db.
Am wondering how do I grab this data? When I hit submit it navigates to the file and displays the JSON. I want to grab the JSON and stay on the same page or move to a different one!
I have kept the php file simple because the data is also used for returning data to my android app.
<div class="well bs-component">
<form id ='formLogin' action="http://localhost/getUsername.php" method="post" class="form-horizontal">
<fieldset>
<legend>Sign In</legend>
<div class="form-group">
<label for="inputEmail" class="col-lg-2 control-label">Email</label>
<div class="col-lg-10">
<input name='email' type="text" class="form-control" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-lg-2 control-label">Password</label>
<div class="col-lg-10">
<input name='password' type="password" class="form-control" id="inputPassword" placeholder="Password">
<div class="checkbox">
<label>
<input type="checkbox"> Checkbox
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="reset" class="btn btn-default">Cancel</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
I believe this cannot be done from a form. I instead used jquery post function to return data

Bootstrap popover is too narrow

http://jsfiddle.net/0y8oy7gf/2/
I have a Bootstrap 3 form in which I have a popover that is placed at the right of the first text input. The popover is triggered on focus of that input, and the trigger is working correctly. My problem is that I'd like for the popover to be wider so that I can have longer lines of text, but it seems to be contained within the parent .col-xs-6. Is there any way to have it be contained by .container-fluid instead, so that it can occupy the empty space on the right?
HTML is below, and the above jsfiddle demonstrates the problem. Thanks!
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="row">
<div class="col-xs-6 col-xs-offset-3 panel panel-gray floating">
<div class="panel-body">
<form action="?" method="POST" id="foo">
<div class="form-group">
<h3>Set your new password</h2>
</div>
<div class="form-group form-group-lg">
<label for="new-password">New password</label>
<input type="password" class="form-control" id="new-password" autofocus data-toggle="popover" data-content="8-20 characters long" data-trigger="focus" data-placement="right" viewport="container">
</div>
<div class="form-group form-group-lg">
<label for="confirm-new-password">Confirm new password</label>
<input type="password" class="form-control" id="confirm-new-password">
</div>
<div class="form-group form-group-lg">
<label for="security-answer">Answer your security question:</label>
<p id="security-question">How many cups of sugar does it take to get to the moon?</p>
<input type="text" class="form-control" id="security-answer">
</div>
<div class="btn-group-lg">
<input type="submit" value="Change password" class="btn btn-primary btn-block" id="btn_changePassword">
</div>
</form>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
You simply need to set the data-container attribute to tell the popover which element to use as it's containing element (see the documentation):
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="row">
<div class="col-xs-6 col-xs-offset-3 panel panel-gray floating">
<div class="panel-body">
<form action="?" method="POST" id="foo">
<div class="form-group">
<h3>Set your new password</h2>
</div>
<div class="form-group form-group-lg">
<label for="new-password">New password</label>
<input type="password" class="form-control" id="new-password" autofocus data-toggle="popover" data-container=".container-fluid" data-content="8-20 characters long" data-trigger="focus" data-placement="right" viewport="container">
</div>
<div class="form-group form-group-lg">
<label for="confirm-new-password">Confirm new password</label>
<input type="password" class="form-control" id="confirm-new-password">
</div>
<div class="form-group form-group-lg">
<label for="security-answer">Answer your security question:</label>
<p id="security-question">How many cups of sugar does it take to get to the moon?</p>
<input type="text" class="form-control" id="security-answer">
</div>
<div class="btn-group-lg">
<input type="submit" value="Change password" class="btn btn-primary btn-block" id="btn_changePassword">
</div>
</form>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
http://jsfiddle.net/0y8oy7gf/3/

Rails and Bootstrap 3: How to get first and last name on same line?

I have been unable to get First and Last name fields on the same line, and at half the width of the other lines - email, password, etc.
I have tried various changes to including the addition of "form-horizonal", col-xs-6, but didn't solve it.
I would like to make the well look like this (currently the are all the same sized, stacked on top of each other):
Excerpt of index.html.erb:
<form class="form-signin col-sm-4 well" role="form">
<h2 class="form-signin-heading">Sign Up</h2><hr>
<form class="form-inline" role="form">
<form class="form-horizontal">
<div class="form-group col-xs-6">
<label class="sr-only" for="#">First name</label>
<input type="text" class="form-control" id="#" placeholder="First name">
</div>
</form>
<form class="form-horizontal">
<div class="form-group col-xs-6">
<label class="sr-only" for="#">Last name</label>
<input type="text" class="form-control" id="#" placeholder="Last name">
</div>
</form>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email address">
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Type email again">
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="Password">
</div>
<div class="form-group">
<div class="">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign Up</button>
</form>
</form>
All help greatly appreciated.
Full index.html.erb -
https://gist.github.com/attatae/11022245
Bootstrap 3 Grid Overview (yes, I looked too):
http://getbootstrap.com/css/#grid
Another related question that I looked at, but didn't solve:
Bootstrap 3: How to get two form inputs on one line and other inputs on individual lines?
Here is what I came up with
I hasten to add that the solution may be different because of the fact that it's bootstrap. My solution doesnt take that into consideration at all, because I'm not familiar with it. It may be as easy as changing some of the classes. Good luck to you...

bootstrap input aligned with button

I'm trying to have on the same line: text, search box and the button "Locate", but the following code seems not working because what I get is: the text "Map for network..." aligned with the input box while the "Locate" button is below the input box. Any suggestion?
<div style="border-color:#FCD229; margin-bottom:0px" class="panel panel-primary">
<!-- Default panel contents -->
<div style="border-color:#FCD229; background-color:#FCD229"class="panel-heading">
<div class="input-group">
<label class="control-label col-lg-8">Map for Network<p class="badge"><?php echo $net_name ?></p></label>
<div class="form-horizontal col-lg-4">
<input id="marker_id" name="address" class="form-control input-sm" type="text" placeholder="node name..">
<span class="input-group-btn">
<button type="submit" class="btn btn-default btn-sm">Locate</button>
</span>
</div>
</div>
</div>
</div>
JSFiddle "Answer"
To cut to the chase - you can look at the result of my tests on JSFiddle: http://jsfiddle.net/eThej/. NOTE - Bootstrap is responsive so you need to make the window with the preview large enough or the controls will wrap to the next line. This is intentional to allow for forms to work on smaller screens (responsive design).
Explanation / Notes
I believe the following example (pulled from the bootstrap site) does something like what you are looking for:
<form class="form-inline" role="form">
<div class="form-group">
<label class="sr-only" for="exampleInputEmail2">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail2" placeholder="Enter email">
</div>
<div class="form-group">
<label class="sr-only" for="exampleInputPassword2">Password</label>
<input type="password" class="form-control" id="exampleInputPassword2" placeholder="Password">
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
<button type="submit" class="btn btn-default">Sign in</button>
</form>
I took your code and applied a few changes to it and got a similar result. First - you are looking for a form with a class of "form-inline". Second, if you are using a column layout I think you probably want "md" columns and not "lg" columns. Finally I think you div's aren't nested correctly. It isn't pretty but I applied these few changes and got much closer to what I think you want. The following is that result:
<div style="border-color:#FCD229; margin-bottom:0px" class="panel panel-primary">
<!-- Default panel contents -->
<div style="border-color:#FCD229; background-color:#FCD229" class="panel-heading">
<form class="form-inline">
<div class="col-md-4">
<label class="control-label">Map for Network</label>
<p class="badge">Test</p>
</div>
<div class="col-md-8">
<div class="form-group"><input id="marker_id" name="address" class="form-control input-sm"
type="text" placeholder="node name.." />
</div>
<button type="submit" class="btn btn-default">Locate</button>
</div>
</form>
</div>
</div>
Again, not a perfect answer but I think it should get you on the right track. Best of luck!
This code seems to be more suitable for what I had in mind.
<div style="border-color:#FCD229; margin-bottom:0px" class="panel panel-primary">
<!-- Default panel contents -->
<div style="border-color:#FCD229; background-color:#FCD229"class="panel-heading">
<label class="control-label col-lg-8">Map for Network Test</label>
<div class="input-group input-group-sm">
<input id="" type="text" class="form-control" placeholder="Node Name">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Locate</button>
</span>
</div><!-- /input-group -->
</div>
</div>