User cannot input information into a bootstrap modal form - html

I've been getting this weird bug with Bootstrap Modals for a few days now, and can't seem to find any sort of answer online. I'd be grateful for any sort of help on this.
My site uses AngularJS + Bootstrap. The specific part I'm working on right now has two buttons that bring up a modal, and a grid below them that shows the user a bunch of info. The weird part is, the button that allows users to create an entry on the grid will bring up a form, but not allow them to edit the first two fields. The second button, which lets users edit an entry on the grid, is pretty much formatted the same as the create button, yet that works fine. This also only occurs on page refresh only, and is resolved after the user clicks the edit button to bring up that modal, then closes that. Afterward, the create modal will work fine. Here is the code for these parts of the site:
Modal Buttons:
<div class="row-fluid" ng-init="getAllSources()">
<!-- Create Source Modal Button -->
<button class="btn btn-success" data-toggle="modal" data-target="#createSource" ng-click="initCreateSource()">+ Create Source</button>
<!-- Edit Source Modal Button -->
<button class="btn btn-primary pull-right" data-toggle="modal" data-target="#editSource">Edit Source</button>
<!-- Sources Grid -->
<div ng-show="visible.grid == true" class="edus-admin-manage-grid" style="margin-left:0;" ng-grid="sourceGridOptions"></div>
</div>
Modals:
<div class="modal fade" id="createSource" tabindex="-1" role="dialog" aria-labelledby="createSourceLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="createSourceModal">Create Source</h4>
</div>
<div class="modal-body" ng-include="'source-create.html'"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="getAllSources()" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success" ng-click="getAllSources()" data-dismiss="modal">Save</button>
</div>
</div>
</div>
</div>
(The Edit Sources Modal looks the exact same as the Create Sources Modal, with the exception of a different link in the ng-include, and some labels here and there)
Here is the part of the code that doesn't 'work' on page refresh:
<form name="form" novalidate>
<div class="row-fluid">
<label for="inputID">* Source Id</label>
<label for="inputName">* Source Name</label>
</div>
<div class="row-fluid">
<input type="text" class="span4" id="inputId" placeholder="Title" ng-model="createSource.createId" required>
<input type="text" class="span8" id="inputName" placeholder="Source Name" ng-model="createSource.createName" required>
</div>
<div class="edus-admin-manage-label-rows row-fluid ">
<label class="edus-admin-manage-label span4" for="inputId">* Activity Name</label>
<label class="edus-admin-manage-label span4" for="inputName">* Activity Label</label>
</div>
<div class="row-fluid form-inline">
<select class="span4" ng-model="activityType.activity" ng-options="value.name for value in multipleActivityTypes" data-style="btn" bs-select></select>
<select class="span4" ng-model="activityType.label" ng-options="value for value in activityLabels" data-style = "btn" bs-select></select>
<input class="btn btn-default span4" type="submit" ng-click="activityTypeSubmit()" value="Add Activity" data-style="btn"/>
</div>
...
</form>
Everything else after the '...' in the third snippet of the code works - I just can't select any options from the pull down menu, or input anything for the Source Id/Name fields. I figured the ngClick I had in the Create Source button that brought up the modal could've been the problem, so I removed that to see if the form was editable - no luck there. Any help is greatly appreciated!
Update:
Originally, I had my HTML organized as so:
<div>
<!-- Modal Buttons -->
</div>
<!-- Modals -->
When I moved my modals back into the divs that contained the buttons, like so:
<div>
<!-- Modal Buttons -->
<!-- Modals -->
</div>
everything worked as intended. This seems like some sort of scoping issue, which I didn't think would cause a problem in HTML - can anyone shed some light on this type of problem?

It's very hard to determine issue when you paste it here wildly. Please use plunker for such issues. And look at this demo in Plnkr
Consider your data structure is like
$scope.activityType = {
'activityType.activity': {}
};
$scope.multipleActivityTypes = [
{
'name': 'asd',
'val': 123
},
{
'name': 'qwe',
'val': 234
}
];
p.s. i should comment this, but not enought pts. so sorry for that

Related

How to get a form field to immediately become active when the page loads?

I have a simple form with one input. How do I get that input form field to immediately highlight for text entry after the page loads?
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title" style="text-align: center;">Enter the number</h4>
...
<!-- Modal body -->
<div class="modal-body mx-auto">
<div class="btn-group-vertical my-5" role="group" aria-label="Basic example">
<input id="phoneNumber" type="tel"></input>
For context: It's a modal that allows the user to call a telephone number from the web page. Currently, you have to click the input field to start typing the number. I want the user to be able to just start typing the number out on page load and have the number fill out in the form field.
Snippet of code above simply shows the key parts of the form for reference. Please let me know if more code is required.
You need to add autofocus to the input
<input id="phoneNumber" type="tel" autofocus>

Buttons not being affected by bootstraps col-md

I have what I think is a very basic problem but to which I cannot find the solution. So I have a form in my rails project. I want to create an input field, and two buttons associated with that field so I can add another type of input field.
If I click on the green button, I append another set of the same 3 fields.
<div class="col-md-2">
<%= f.input :select1, collection: #traffic_vault.sort + [["------ Aggregations ------ ", ""]] + #traffic_vault_aggregations.sort, include_blank: false, label: "Select Dimensions (*)", input_html: {class: "remember_timestamp", type: "text" } %>
</div>
<div class="col-md-2">
<button type="button" class="btn btn-success" onclick="apply_function(0)">Apply Function</button>
</div>
<div class="col-md-2">
<button type="button" class="btn btn-success" onclick="rename(0)">Rename It</button>
</div>
My problem is that the input field is working fine by taking exactly the col-md that I put there, but the buttons are not, they are taking slightly less space, not exactly col-md-2. So, when adding more fields to the first image, since the buttons are not exactly col-md-2, I get this:
I found out the problem is with the buttons because if I change it to inputs, it is working perfectly.
As we can see, they all have the same space between them, and each of them is col-md-2, so when adding 6 of these fields, you have col-md-12, so anymore fields added will be placed below and so on, but not with the buttons.
What is the problem?
solution: thanks to Siim for the answer. By placing style="width:100%;" button will take all available width. But still, i have a problem where, even if the buttons are col-md-2, like the inputs from before, if i add a 3rd set of fields, its not being placed correctly like in the 3rd image with the inputs, where the new set is placed at the beginning of another row.
Add w-100 class to the button. This tells the button to take up 100% of the available space.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-sm-4">
<label>
<input class="form-control">
</div>
<div class="col-sm-4">
<button type="button" class="btn btn-success">
btn
</button>
</div>
<div class="col-sm-4">
<button type="button" class="btn btn-success w-100">
btn
</button>
</div>
</div>
</div>

Why is this html pattern of input type="checkbox" lable for breaking the ngx-bootstrap modal dialog

icheck-bootstrap is a pure css checkboxes and radio buttons for Twitter bootstrap. This implies it will work with any of the frontend libraries. At least that's the way I figured it... And indeed, his use from the readme of his github page for the library :Link to icheck-bootstrap demo with docs Does work it just has a side effect that I can live with.
In at lease one place where I'm trying to use this library, the component is in a modal dialog that is used to login to the site. Below is the html template code for the component:
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close" aria-hidden="true" (click)="hideModal()">
<span aria-hidden="true">×</span>
</button>
<h3 class="modal-title-site text-center"> Login to Rove </h3>
</div>
<form #f="ngForm" (ngSubmit)="onSubmit()">
<div class="modal-body">
<div class="form-group login-username">
<div>
<input name="log" id="login-user" class="form-control input" size="20"
[(ngModel)]="model.email" placeholder="Enter User Email" type="email">
</div>
</div>
<div class="form-group login-password">
<div>
<input name="Password" id="login-password" class="form-control input" size="20"
[(ngModel)]="model.password" placeholder="Password" type="password">
</div>
</div>
<div class="col-lg-12">
<div class="form-group">
<span class="checkbox login-remember">
<input name="rememberme" value="forever" checked="checked"
[(ngModel)]="model.rememberMe" type="checkbox">
<label for="rememberme">Remember Me</label>
</span>
</div>
</div>
<div>
<div>
<input name="submit" class="btn btn-block btn-lg btn-primary" value="LOGIN" type="submit">
</div>
</div>
</div>
</form>
<div class="modal-footer">
<p class="text-center">
Not here before? <a data-toggle="modal" data-dismiss="modal"
href="#ModalSignup">Sign Up.</a> <br>
Lost your password?
</p>
</div>
The code above is without the icheck-bootstrap implemented code. Below I have changed the key lines of code that will implement the checkbox as per the readme documention on the github site
<div class="icheck-success checkbox login-remember">
<input id="rememberme" value="forever" checked="checked"
[(ngModel)]="model.rememberMe" type="checkbox">
<label for="rememberme">Remember Me</label>
</div>
this code works as per the readme, unfortunately, after the dialog has been closed the modality of the modal dialog stays and the main page behind it will not allow any input from keyboard or mouse.
Note the input tag in the effective lines, I have change from the name attribute, to the id attribute. That seems wrong to me but, it is as the documentation suggests and, the only way it will completely work. If I do not change the attribute from name to id the checkbox changes to the correct style but it will not check to show a true state. In fact if I remove the icheck-success class from the class attribute of the above div line the behavior is identical and the component will still not take input after the dialog box has been closed if I use the id attribute instead of the name attribute.
I'm using Angular V9 and the dialog component that I am using is from the Valor Software ngx-bootstrap library and, as stated, it works perfectly when I code the html input tag with the name attribute. Does any know of a workaround or possibly what is happening here? the styling is what I want on the site but not at the cost of not having the login dialog effectively lock the site up after you login.
Thanks for any info that you may have on this issue.
I have fix the problem I was having. The first part of the problem was that I was not asking the right question. I have edited the question to ask it in a better way, I think.
I have fixed the problem with the html below:
<div class="icheck-success checkbox login-remember">
<input id="rememberme" name="rememberme" [(ngModel)]="model.rememberMe" type="checkbox">
<label for="rememberme">Remember Me</label>
</div>
it seems I had to have a name attribute in the input tag for some reason that I'm not clear about at all but, this is what I did to get the modal dialog to truly clear from the page after close.

Why a second Bootstrap 3 Button (not marked as 'submit') is submitting my form? [duplicate]

This question already has answers here:
How to prevent buttons from submitting forms
(20 answers)
Closed 4 years ago.
My Bootstrap 3 edit form had initially only a Submit button that worked perfectly. When I added another button to implement a 'Cancel' option, it didn't work as expected, and a click on it is submitting the form (and saving changes). Of course I didn't mark this second button as 'Submit', not being intended for that.
My HTML/PHP code looks like this:
<form method='POST' action='savechanges.php'>
<div class="form-group">
<label for="IdDataList">List Id</label>
<input type="text" class="form-control" id="IdDataList" readonly value="<?php echo $row['IdDataList']; ?>">
</div>
<div class="form-group">
<label for="DataListName">List Name</label>
<input type="text" class="form-control" id="DataListName" name="DataListName" value="<?php echo $row['DataListName']; ?>">
</div>
<div class="form-group">
<label for="DataListDescription">Description</label>
<input type="text" class="form-control" id="DataListDescription" name="DataListDescription" value="<?php echo $row['DataListDescription']; ?>">
</div>
<!-- Submit button -->
<div class="form-group col-sm">
<button class="btn btn-primary" name="saveall" type="submit" >Save changes</button>
</div>
<!-- Here the second 'Cancel' button -->
<div class="form-group col-sm">
<button class="btn btn-primary" name="goback" onclick="window.location.href='anotherpage.php'">Cancel</button>
</div>
</form>
Must be something obvious but I can't see what's going wrong...
Thanks in advance!
Credit for this answer goes to #Chilll007, as I decided to close this question myself.
The current HTML standard, as adopted by most browsers, states that the type attribute should be used to differentiate the button's behavior, defaulting to 'submit' type.
Buttons that don't serve to this purpose should be marked as generic with type='button'. To get hyperlink behavior you can define actions through Javascript or with an <a href=''></a> tag:
Cancel

Use div in multiple locations

I want to know if you can use one div and have it pop on with CSS in other places to save space and make things more organized. I have a set of code that uses the same lines for a lot of it, it's buttons and what have you in a pop up. So I want to sit the div in a nice spot and use CSS to have it pop up under different pop ups
<div class = "example">
<ul class = "list">
<li>example</li>
<select name = "example">
<option value = "0">0</option>
</select></li>
<input ...example text...>
</ul>
</div>
So that sits inside another div that is an image and some text that CSS has pop up when a link is clicked, it's just a list of things to pick for a e-commerce page, I have to rewrite it each for each new item, the CSS I have for it just sets the pop up display and I have jquery for the pop up action. Instead of having that said code above being rewritten each time I want it once and use CSS or java to have it pop up with all of the pop ups
You could bootstrap and a modal for popups since you will have an easier time with them and you can do all sorts of things with modals.
And Bootstrap is INCREDIBLY easy to use
Bootstrap Modal example
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
This is the example from W3 Schools - I know it seems like a lot, but Bootstrap will change your web design world :)
save the code you wrote (ex: as example.php).
then you can use it with other pages using an include/require:
for example: (example2.php)
include 'example.php';
or
require 'example.php';
You can use this syntax anytime and anywhere within the php file.