In Vue, I've tried naming buttons, but after the submit, the data isn't posted.
<div id="app">
<form ref="myForm" method="POST" v-on:submit.prevent="onSubmit($event)" action="/push" class="needs-validation" id="myForm" novalidate="true">
<div class="form-group">
<label for="cannedListLabel">Canned List</label>
<input v-model="cannedlist" ref="cannedlist" type="text" class="form-control" name="fileListFile" id="filelist"
:disabled="!!individuallist" v-on:submit.prevent="onSubmit" />
</div>
<div class="form-group">
<label for="pathListLabel">Path List</label>
<textarea v-model="individuallist" ref="cannedlist" :disabled="!!cannedlist" class="form-control" rows=10 name="fileListRaw" id="files"></textarea>
</div>
<div class="form-group">
<button v-on:submit.prevent="onSubmit($event)" type="submit" name="button1" value="submit" id="submitButton" class="btn btn-primary" :disabled="isDisabledButton">Submit</button>
<button v-model="clickedButton" v-on:submit.prevent="onSubmit($event)" type="submit" name="button2" value="checkOnly" id="checkOnlyButton" class="btn btn-primary" :disabled="isDisabledButton">Check Only</button>
</div>
</form>
</div>
The onSubmit function submits the form using this.$refs.myForm.submit(); If I change the type of the button from "submit" to "button", the submit() function no longer works, which I don't completely understand. Why is that, by the way?
As suggested, I change the type to button, and used the #click handler and while it does not work, here's changed diff:
<div class="form-group">
<button #click="onSubmit($event)" type="button" name="btn" value="submitButtonPressed" id="submitButton" class="btn btn-primary mb-2" :disabled="isDisabledButton">Submit</button>
<button #click="onSubmit($event)" type="button" name="btn" value="checkOnlyButtonPressed" id="checkOnlyButton" class="btn btn-primary" :disabled="isDisabledButton">Check Only</button>
</div>
Related
I'm trying to bind an image uploading but facing the problem with sending this image to the controller.
I'm using Razor and .net core 2.2.
My Controller
[HttpPost(nameof(MealController))]
[Authorize(Roles = UserRoles.Moderator)]
public IActionResult Update(MealModel meal, IFormFile pic)
{
if (ModelState.IsValid)
{
try
{
var changedMeal = _mapper.Map<MealModel, MealDTO>(meal);
_mealService.Update(changedMeal, pic);
}
catch (Exception e)
{
return NotFound();
}
return RedirectToAction("Index");
}
return View(meal);
}
My form
<form class="form" method="post" asp-controller="Meal" asp-action="Update">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Продукт</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="product">
<div class="product-img">
<div class="selector">
<img src="#Model.ImagePath" class="img-thumbnail" id="selectedImg" alt="Product Image"/>
<div class="form-group">
<input type="file" class="custom-file-input" id="pic-input" name="pic"
onchange="readURL(this, 'selectedImg')">
#* <label class="custom-file-label" for="pic-input"></label> *#
</div>
</div>
</div>
<div class="product-info">
<div class="form-group name">
<label for="name">Назва продукту</label>
<input class="form-control" type="text" placeholder="Назва" id="name" name="name" asp-for="Name"
value="#Model.Name">
</div>
<div class="form-group">
<label for="name">Ціна</label>
<input class="form-control" placeholder="Price" id="price" type="number" asp-for="Price"
value="#Model.Price">
</div>
<div class="form-group">
<label for="name">Вага</label>
<input class="form-control" id="weight" type="number" asp-for="Weight"
value="#Model.Weight">
</div>
<div class="comments">
<textarea class="form-control" rows="3" cols="5" placeholder="Склад" asp-for="Description" value="#Model.Description"></textarea>
</div>
<input type="hidden" asp-for="MealGroupId" value="#Model.MealGroupId"/>
<input type="hidden" asp-for="Id" value="#Model.Id"/>
#* <input type="hidden" asp-for="ImagePath" value="#Model.ImagePath"/> *#
</div>
</div>
</div>
<div class="modal-footer">
<div class="action-button">
<button type="submit"
class="btn btn-success ok-button">
<span>Додати</span>
</button>
<button type="reset"
class="btn btn-danger remove-button">
<span>Відмінити</span>
</button>
</div>
</div>
</div>
</form>
When I debug, IFormFile is always null. I tried using [FromForm] but it didn't help. I googled and found out that my name in form and parameter name was different but it had effect. Could you, please give me a little hint on how I can solve it. Thank you and have a good day!
You have to specify <form>'s enctype attribute set to multipart/form-data to be able to send files to server
<form class="form" method="post" asp-controller="Meal" asp-action="Update" enctype="multipart/form-data">
I'm using VueJS to have it dynamically add new inputs once a button is clicked. With my current code it is not adding the inputs. Why is that?
<div class="row" v-for="count in task.pos.length">
<div class="col-12 col-sm-6">
<div class="form-group">
<label class="control-label" for="po_number">Order Number:</label>
<input id="po_number" class="form-control" type="text" placeholder="Purchase Order" v-model="task.pos[count-1].purchase_order">
</div>
</div>
<div class="col-12 col-sm-6">
<div class="form-group">
<label class="control-label" for="po_amount">Order: Amount:</label>
<input id="po_amount" class="form-control" type="text" placeholder="Purchase Amount" v-model="task.pos[count-1].po_amount">
</div>
</div>
</div>
<div class="form-group">
<button class="btn btn-success btn-xs mb5 text-white" v-on:click.prevent="addEditNewPOEntry()"><i class="fa fa-plus"></i> Add PO</button>
<button class="btn btn-warning btn-block btn-xs" v-on:click.prevent="saveEdit(task)">Done</button>
</div>
addEditNewPOEntry: function(){
this.newTask.po.push({'purchase_order': this.task.purchase_order, 'purchase_amount': this.task.purchase_amount});
this.$set(this, 'task.pos.length', this.task.pos.length+1);
},
I have a set of javascript buttons nested within another set of javascript buttons. Below is my fiddle.
<div data-toggle="buttons" style="padding: 20px;">
<div class="col-xs-6">
<div class="btn btn-info" style="padding: 20px;">
<div class="row">
<div class="col-sm-12">
<div class="btn-group btn-group-justified btn-group-lg" data-toggle="buttons">
<label class="btn btn-primary">
<input type="radio" name="package" value="RP101" data-duration="7" />1</label>
<label class="btn btn-primary">
<input type="radio" name="package" value="RP102" data-duration="14" />2</label>
<label class="btn btn-primary">
<input type="radio" name="package" value="RP103" data-duration="21" />3</label>
<label class="btn btn-primary">
<input type="radio" name="package" value="RP104" data-duration="28" />4</label>
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-6">
<div class="btn btn-info" style="padding:20px;">
<div class="row">
<div class="col-sm-12">
<div class="btn-group btn-group-justified btn-group-lg" data-toggle="buttons">
<label class="btn btn-primary">
<input type="radio" name="package" value="RP201" data-duration="7" />1</label>
<label class="btn btn-primary">
<input type="radio" name="package" value="RP202" data-duration="14" />2</label>
<label class="btn btn-primary">
<input type="radio" name="package" value="RP203" data-duration="21" />3</label>
<label class="btn btn-primary">
<input type="radio" name="package" value="RP204" data-duration="28" />4</label>
</div>
</div>
</div>
</div>
</div>
</div>
http://jsfiddle.net/q4xLs9f8/
My issue is that when I click the top level button, it logs out the nested radio button as if it was already selected. I don't have anything marked as selected or checked.
Does nesting buttons like this cause problems?
Nesting is certainly not intended. What happens is that it the javascript is selecting the last radio input in the group and selects that.
I have a multi-step reg form with each step in a fieldset,i am using bootstrap validator for validation.I made the 'next' button in first step to toggle validation.And it works well...
The problem i have is,i have to prevent going to next step on an error.
Now, validation works on clicking 'next'in first step but immediately passes to next step.
I want to stay there until validation is success...
How to do this?
i m giving my chunk of code...i have all libraries included...
...
<fieldset id="first_step">
<h2 class="fs-title">Create your account</h2>
<div class="form-group">
<label class="col-md-3 control-label">Username</label>
<div class="col-md-9">
<input type="text" class="form-control" name="uname" />
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Password</label>
<div class="col-md-9">
<input type="password" class="form-control" name="pwd" />
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Confirm Password</label>
<div class="col-md-9">
<input type="password" class="form-control" id="cpwd" />
</div>
</div>
<input type="button" name="next" id="next" class="next action-button" value="Next" />
</fieldset>
<fieldset>
<h2 class="fs-title">Personal Details</h2>
<h3 class="fs-subtitle"></h3>
<div class="form-group">
<label class="col-md-3 control-label">*Register Number</label>
<div class="col-md-9">
<input type="text" class="form-control" id="Text1" name="reg" />
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">*Name</label>
<div class="col-md-9">
<input type="text" class="form-control" id="Text2" name="stname" />
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-offset-3 col-md-12">
</div>
</div>
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="submit" id="sub_but" name="submit" class="submit action-button" value="Submit" />
</fieldset>
<script type="text/javascript">
$(".next").click(function() {
$('#msform').data('bootstrapValidator').validate();
//prevent here????
//Script to slide first fielset
}
$(".previous").click(function() {
//Script to slide back to first fieldset
}
</script>
Weird issue. When the button that launches the modal window is located inside the form div, the modal window fails to launch. Chrome says
"Resource interpreted as Script but transferred with MIME type text/x-js:"
I already put a type for the source js but it didnt help. I also moved the call to earlier on in the page and that didnt work. The really weird part is, if I move the button outside of the form div, the modal opens just fine with no issue. Has anyone experienced this and can point me in the right direction. Thanks in advance
Edit: Here is the code(I cut out the content)
<div class="container">
<form class="form-inline" role="form">
<div class="form-group">
<label for="companyName">Company Name</label>
<input type="text" class="form-control" id="companyName" placeholder="Company Name">
</div>
<div class="form-group">
<label for="chainCode">Chain Code</label>
<input type="text" class="form-control" id="chainCode" placeholder="Chain Code">
</div>
<div class="form-group">
<label for="nCode">N-Code</label>
<input type="text" class="form-control" id="nCode" placeholder="N-Code">
</div>
<button type="submit" class="btn btn-success">Search</button>
<button class="btn btn-warning" data-toggle="modal" data-target="#advancedModal"> Advanced
<span class="glyphicon glyphicon-cog"></span>
</button>
</form>
<!-- Advanced Modal -->
<div class="modal fade" id="advancedModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Advanced Options</h4>
</div>
<div class="modal-body">
<form role="form" id="myForm" method="post">
<div class="form-group">
</form><!-- end advanced form -->
</div><!-- end modal-body -->
<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><!-- end modal-footer -->
</div><!-- end modal content -->
</div><!-- end modal dialog large -->
</div><!-- end Advanced Modal -->
</div><!-- End Form Container -->
somehow it seems to me, that bootstrap gets confused with the button in the form somehow.
so try using
<a class="btn btn-warning" data-toggle="modal" data-target="#advancedModal">
Advanced <span class="glyphicon glyphicon-cog"></span>
</a>
instead of
<button class="btn btn-warning" data-toggle="modal" data-target="#advancedModal">
Advanced <span class="glyphicon glyphicon-cog"></span>
</button>
It should work, and looks just the same.