Bootstrap 3 - Auto collapse wells. How...? - twitter-bootstrap-3

Probably a simple question for someone, but hard to figure out for me.
I am using the following html:
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#waarom" aria-expanded="false" aria-controls="waarom">Button A</button>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#spelregels" aria-expanded="false" aria-controls="spelregels">Button B</button>
<div class="collapse" id="waarom">
<div class="well waarom">
<p>Ipsum Lorem text (button A)</p>
</div>
</div>
<div class="collapse" id="spelregels">
<div class="well spelregels">
<p>Ipsum Lorem (button B)</p>
</div>
</div>
Collapse works, however, they can be expanded both. This is not the result what I want. Both start collapsed (= good). I click on 'Button A' it expands, then I click 'Button B' then contents of B should be visible and contents under 'Button A' should be hidden.
So in short; press B, show B contents (and hide A contents).
Sorry if I don't make sense, trying to do my best at English here. :)
Thank you for your time and solutions. The examples I could find only showed this for the 'Accordion', which I don't want. So, maybe this is not even possible.

You can wrap it in a div and use a bit of jquery http://jsfiddle.net/2Dj7Y/2087/
<div id="accordion">
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#waarom" aria-expanded="false" aria-controls="waarom">Button A</button>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#spelregels" aria-expanded="false" aria-controls="spelregels">Button B</button>
<div class="collapse collapse-well" id="waarom">
<div class="well waarom">
<p>Ipsum Lorem text (button A)</p>
</div>
</div>
<div class="collapse collapse-well" id="spelregels">
<div class="well spelregels">
<p>Ipsum Lorem (button B)</p>
</div>
</div>
</div>
$('.collapse-well').on('show.bs.collapse', function () {
$(this).closest("#accordion")
.find(".collapse.in")
.not(this)
.collapse('toggle')
})

Bootstrap uses the "collapse" and "collapse.in" classes to collapse and expand div's respectively.
You could create some javascript which is called on each button press and changes the classes to open and close the required div's using the following code.
<script>
function expandA(){
document.getElementById("waarom").className = "collapse.in"; //Open A
document.getElementById("spelregels").className = "collapse"; //Close B
}
function expandB(){
document.getElementById("waarom").className = "collapse"; //Close A
document.getElementById("spelregels").className = "collapse.in"; //Open B
}
</script>
Following this you would call the functions when a click event occurs
<button class="btn btn-primary" type="button" onclick"expandA()">Button A</button>
<button class="btn btn-primary" type="button" onclick"expandB()">Button B</button>

Related

ASP.Net Core MVC Bootstrap 4 Modal Form Submit Not Working

I'm writing a ASP.Net Core 2.2 application, trying unsuccessfully to implement a Bootstrap 4 modal view to confirm the deletion of records from a database/table view.
Each row of the table has a delete button. When the delete button for a given row in the table is clicked, the modal delete confirmation box appears as expected. When the user click on the button to confirm the deletion of the record, the modal delete confirmation box disappears, and nothing happens.
Here is the Razor code that generates the rows in the table:
<tbody>
#foreach (LearningObjective item in Model.LearningObjectives)
{
<tr>
<td>#Html.DisplayFor(model => item.Sentence)</td>
<td>#Html.DisplayFor(model => item.Verbs)</td>
<td>#Html.DisplayFor(model => item.Measurables)</td>
<td>#Html.DisplayFor(model => item.Blooms)</td>
<td>#Html.DisplayFor(model => item.Levels)</td>
#if (ViewBag.Title == "Build and Analyze Learning Objectives")
{
<td>
<a id="deleteCustomerModal"
data-toggle="modal"
asp-action="DeleteLearningObjective"
asp-route-id="#item.Id"
data-target="#modal-delete"
class="btn btn-sm btn-danger">
<i class="fa fa-trash-o"></i>
Delete
</a>
</td>
}
</tr>
}
</tbody>
Here is an example of how the code above renders an actual table row (from the page source):
<tr>
<td>analyze all the fun things we can do with this app</td>
<td>Analyze, Do</td>
<td>Yes, No</td>
<td>Yes, No</td>
<td>4, -</td>
<td>
<a id="deleteCustomerModal"
data-toggle="modal"
data-target="#modal-delete"
class="btn btn-sm btn-danger"
href="/Home/DeleteLearningObjective/296">
<i class="fa fa-trash-o"></i>
Delete
</a>
</td>
</tr>
That href above is correct.
Here is the HTML for the modal form:
<form asp-action="DeleteLearningObjective" role="form"><
<div class="modal fade" id="modal-delete" tabindex="-1" role="dialog" aria-labelledby="modalDeleteLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modalDeleteLabel">Delete Learning Objective</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body form-horizontal">
Are you sure you want to delete this learning objective?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-danger" id="modalDeleteButton">Delete</button>
</div>
</div>
</div>
</div>
</form>
Here is the Javascript:
$(function () {
// boostrap 4 load modal example from docs
$('#modal-delete').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget); // Button that triggered the modal
var url = button.attr("href");
var modal = $(this);
// note that this will replace the content of modal-content everytime the modal is opened
modal.find('.modal-content').load(url);
});
$('#modal-delete').on('hidden.bs.modal', function () {
// remove the bs.modal data attribute from it
$(this).removeData('bs.modal');
// and empty the modal-content element
$('#modal-delete .modal-content').empty();
});
});
Stepping through:
*Table rows are rendered correctly, and each rows href value is correct.
*The modal appears as expected.
*When the modals Delete button is clicked, the jQuery code executes. The code successfully finds and extracts the correct href value from the table row.
*The last line of the jQuery code (modal.find('.modal-content').load(url);) executes, but I do see the following type of error in Chrome's Debug console:
GET https://localhost:44389/Home/DeleteLearningObjective/296 405
*The modal closes
So, the href value from the table row never actually gets passed to the modal. I suspect that is because it is being interpreted as a GET request rather than a POST request (per the error).
I've been Googling and trying to solve this for two days and I am about to take a hammer to my computer.
Make the following modification :
1.In <a>Delete</a> ,remove asp-action and asp-route-id,then add the data-id in order to send the id of delete-item to the controller
<a id="deleteCustomerModal"
data-toggle="modal"
data-target="#modal-delete"
data-id="#item.Id"
class="btn btn-sm btn-danger">
<i class="fa fa-trash-o"></i>
Delete
</a>
2.Add id="myForm" to the form , and add the hidden input which is used to get the id of the deleted item in the modal-body section
<form asp-action="DeleteLearningObjective" role="form" id="myForm">
<div class="modal fade" id="modal-delete" tabindex="-1" role="dialog" aria-labelledby="modalDeleteLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modalDeleteLabel">Delete Learning Objective</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class=" form-horizontal">
Are you sure you want to delete this learning objective?
<input hidden name="id"/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-danger" id="modalDeleteButton">Delete</button>
</div>
</div>
</div>
</div>
</form>
Javascript
<script>
$(function () {
$('#modal-delete').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget); // Button that triggered the modal
var id = button.data("id");
var modal = $(this);
modal.find('.modal-content input').val(id);
});
$("#modalDeleteButton").click(function () {
$("#myForm").submit();
});
});
Result:

Why is using v-for different from placing every item separately in this case? Also Bootstrap content centering

I was experimenting with my newly acquired knowledge of Vue and Bootstrap when I ran on a behaviour that I couldn't explain.
<div class="col-sm-4" class="text-center">
<p v-html="mensagem"></p>
<button v-for="tipo in tiposJogadas" class="btn btn-primary" #click="escolhe(tipo)">{{ tipo }}</button>
<div class = "row">
<div class = "column-sm-12" class="text-center">
<button class="btn btn-danger" #click="reset()">Reiniciar</button>
</div>
</div>
</div>
Renders three buttons on glued on the other. Whileas if I replace the v-for statement for three button statements like this:
<div class="col-sm-4" class="text-center">
<p v-html="mensagem"></p>
<button class="btn btn-primary" #click="escolhe('pedra')">Pedra</button>
<button class="btn btn-primary" #click="escolhe('papel')">Papel</button>
<button class="btn btn-primary" #click="escolhe('tesoura')">Tesoura</button>
<div class = "row">
<div class = "column-sm-12" class="text-center">
<button class="btn btn-danger" #click="reset()">Reiniciar</button>
</div>
</div>
</div>
It renders everything perfectly. I don't understand why, since when I inspect the final elements in both scenarios they are the same.
I wasn't gonna ask, but I also couldn't manage to center the red reset button. Since I'm already asking a question, it'd be nice to know why what I've tried doesn't work as well.
Because the line returns in the HTML are adding whitespace between the buttons. v-for isn't. v-for is rendering the same as...
<div class="col-sm-4">
<p v-html="mensagem"></p>
<button class="btn btn-primary" #click="escolhe('pedra')">Pedra</button><button class="btn btn-primary" #click="escolhe('papel')">Papel</button><button class="btn btn-primary" #click="escolhe('tesoura')">Tesoura</button>
<div class="row">
<div class="column-sm-12">
<button class="btn btn-danger" #click="reset()">Reiniciar</button>
</div>
</div>
</div>
You could add a margin-right (mr-1) to each button...
<button v-for="tipo in tiposJogadas" class="btn btn-primary mr-1" #click="escolhe(tipo)">{{ tipo }}</button>
https://www.codeply.com/go/pXOPYAA8St

Bootstrap modal works on it's own, but not from button click

Based on the live demo in the Bootstrap examples, I've made this fiddle to show a dialog.
Then this fiddle should bring up the dialog on click, but is not working:
<button type='button' data-toggle='modal' data-target='#myModal'>Click here</button>
It may be obvious, but what am I missing from the above-linked live demo?
I had some trouble getting this to work, I'm not entirely sure, but I think that the issue was mainly the 'External Resources' on JSFiddle.
I have added the jQuery CDN to the fiddle, you can find it here:
https://jsfiddle.net/7ww5ra98/1/
Here is the HTML:
<button type="button" data-toggle="modal" data-target="#myModal">Click Here</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">Popup Dialog</h4>
</div>
<div class="modal-body">
<p>Wow, it works!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Reset Password</button>
</div>
</div>
</div>
</div>
Hope you found this useful.

twitter bootstrap 3++ modal window doesn't load

My twitter bootstrap modal window isn't loading properly; it is faded when it loads. Here is an image demonstrating the problem.
I have tried a few things but cannot resolve the issue.
My code is:
<button type=\"button\" class=\"btn btn-danger btn-mini\" data-toggle=\"modal\" data-target=\"#myModal\" href=\"#myModal\">
<div id=\"myModal\" class=\"modal fade\">
<div class=\"modal-dialog\">
<div class=\"modal-content\">
<div class=\"modal-header\">
<button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\">×</button>
<h4 class=\"modal-title\">Confirmation</h4>
</div>
<div class=\"modal-body\">
<p>Do you want to save changes you made to document before closing?</p>
<p class=\"text-warning\"><small>If you don't save, your changes will be lost.</small></p>
</div>
<div class=\"modal-footer\">
<button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">Close</button>
<button type=\"button\" class=\"btn btn-primary\">Save changes</button>
</div>
</div>
</div>
</div></div>
There's invalid syntax in your code example (HTML and Bootstrap). It seems like you're trying to load a warning button before the modal, but you're missing text for the button as well as the closing button tag. Here's a Bootstrap 3 example that should accomplish what you described:
<button class="btn btn-danger btn-xs" data-toggle="modal" data-target="#myModal" href="#myModal">
Save Now!
</button>
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Confirmation</h4>
</div>
<div class="modal-body">
<p>Do you want to save changes you made to document before closing?</p>
<p class="text-warning"><small>If you don't save, your changes will be lost.</small></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
Edit the button text to read what you'd like. "Save Now!" is just an example for illustration purposes.

how to create a chat input box in bootstrap 3?

I want to create somthing that in bootsrap:
[colorpicker | input box | button] [toggle button]
I have used:
<div class="input-group">
<input type="text" class="form-control">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Send</button>
<button class="btn btn-default">Users</button>
</span>
</div>
However, I don't know what colorPicker for bootstrap I should use (only 9 colors pickers) and how to add it on left side.
Any help is welcome.
Fiddle: http://jsfiddle.net/5B5v5/
Since I think you're saying you want a color picker with just 9 color options, I would go with a dropdown instead of a fully baked color-picker plugin... like so:
<div class="form-inline">
<div class="input-group">
<div class="input-group-btn">
<!-- COLOR PICKER -->
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Color <span class="caret"></span></button>
<ul class="dropdown-menu" role="menu">
<li><span style="color:cyan" class="glyphicon glyphicon-tint"></span> Cyan</li>
<li><span style="color:blue" class="glyphicon glyphicon-tint"></span> Blue</li>
<li><span style="color:magenta" class="glyphicon glyphicon-tint"></span> Magenta</li>
<li>...more...</li>
</ul>
<!-- END COLOR PICKER -->
</div><!-- /btn-group -->
<input type="text" class="form-control">
</div>
<button class="btn btn-primary" type="button">Send</button>
<button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-user"></span></button>
</div>
</div>
DEMO: http://www.bootply.com/ecziRvg9Jg
If you do find a true color picker that lets you do 9 colors only, attach it to the button I commented in the code.