I can't find the problem to set value in my form. It's only brings me the first value and the mistake is ERROR Error: Cannot find form control at index 1
at FormArray._throwIfControlMissing. Does anyone know what the right way would be like?
in my components
public setValueForm(): void {
const values = {
'_id': this.priceList._id,
'name': this.priceList.name,
'percentage' : this.priceList.percentage,
'allowSpecialRules' : this.priceList.allowSpecialRules,
'rules' : this.priceList.rules || []
};
this.priceListForm.setValue(values);
}
and my html
<div class="row tab-content">
<div formArrayName="rules" *ngFor="let rule of priceListForm.get('rules').controls; let i = index;">
<div [formGroupName]="i">
<div class="row">
<div class="form-group col-md-4">
<label for="category" class="control-label">Rubro:</label>
<select class="form-control" formControlName="category">
<option *ngFor="let category of categories"
[value]="category._id"
[disabled]="readonly">
{{category.description}}
</option>
</select>
</div>
<div class="form-group col-md-4">
<label for="make" class="control-label">Marca</label>
<select class="form-control" formControlName="make">
<option *ngFor="let make of makes"
[value]="make._id"
[disabled]="readonly">
{{make.description}}</option>
</select>
</div>
<div class="form-group col-md-3">
<label for="percentage" class="control-label">Porcentaje:</label>
<div class="input-group">
<input type="number" class="form-control" formControlName="percentage" name="percentage" id="percentage" [readonly]="readonly"/>
</div>
<div *ngIf="formErrors.percentage" class="alert alert-danger">
{{ formErrors.percentage }}
</div>
</div>
<div class="col-md-1">
<label class="control-label">Acción:</label>
<button type="button" class="btn btn-success btn-sm" (click)="addRule()">
<i class="fa fa-plus"></i>
</button>
<button type="button" class="btn btn-danger btn-sm" (click)="deleteRule(i)">
<i class="fa fa-trash-o"></i>
</button>
</div>
</div>
</div>
</div>
</div>
Resolved
let control = <FormArray>this.priceListForm.controls.rules;
this.priceList.rules.forEach(x => {
control.push(this._fb.group({
'_id': x._id,
'percentage': x.percentage,
'make' : x.make,
'category' : x.category
}))
})
Related
I make an application in vuejs3 and quasar, here i am using q-select but selected option and select arrow is not welle displayed here the display
i have no specific CSS, here my component
<template>
<teleport v-if="show" to="#modals">
<div class="modal" tabindex="-1" role="dialog" style="overflow-y: scroll">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Changer le status de la commande N° {{ orderId }}</h5>
</div>
<form class="status-form" #submit.prevent="onSubmit">
<div class="modal-body">
<Comment :id_order="orderId" />
<!-- <select id="state" v-model="selected">
<option
v-for="state in orderStates"
:value="state.id"
:key="state.id"
>
{{ state.name }}
</option>
</select> -->
<q-select outlined v-model="state" name="state" :options="orderStates" label="state.name" option-value="id"
option-label="name" fill-input use-input/>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">
<slot name="loading" v-if="loadingState">Loading...</slot>
<slot name="loading" v-if="!loadingState"
>Changer le status</slot
>
</button>
<button
type="button"
class="btn btn-secondary"
#click="
$emit('update:show', !show),
$emit('update:orderDetails', []),
$emit('update:orderId', null),
$emit('update:selected', null)
"
>
Fermer
</button>
</div>
</form>
</div>
</div>
</div>
any idea ?
I am using bootstrap 4, jQuery 3.3.1 and datepicker (http://www.eyecon.ro/bootstrap-datepicker/)
I have three issues:
The Calendar icon is not the size of the input box
When submit without selecting the date, bootstrap validation message not working.
Auto close is not working.
$(document).ready(function()
{
$('#depositeDate').datepicker({
"setDate": new Date(),
"autoclose": true
});
})
<div class="form-group row">
<label for="depositeDate" class="col-sm-4 col-form-label col-form-label-lg">Deposit Date</label>
<div class="col-sm-2 input-group date">
<input type="text" class=" text-input form-control" id ="depositeDate" placeholder="MM/DD/YYYY">
<div class="input-group-addon">
<i class="fas fa-calendar-alt fa-3x" style="color:RED"></i> </div>
<div class="invalid-feedback">
Please enter a valid Order Number.
</div>
</div>
</div>
The Calendar icon is not the size of the input box
The markup for input group addon is changed in Bootstrap 4.0 stable
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username" aria-describedby="basic-addon2">
<div class="input-group-append">
<span class="input-group-text" id="basic-addon2">#example.com</span>
</div>
</div>
Your code should be
<div class="input-group date" >
<input type="text" class="form-control" id ="depositeDate" placeholder="MM/DD/YYYY">
<div class="input-group-append">
<span class="input-group-text" id="basic-addon2"><span class="fa fa-calendar"></span></span>
</div>
</div>
3.Auto close is not working.
I don't see setting like "autoclose": true , we should explicitly call to close the datepicker.
.on('changeDate', function(ev) {
checkout.hide();
})
<div class="form-group row justify-content-center align-items-center">
<label for="depositeDate" class="col-sm-3 col-form-label">Deposit Date</label>
<div class="col-sm-3 input-group date" >
<input type="text" class="text-input form-control" id ="depositeDate" placeholder="MM/DD/YYYY">
<div class="input-group-addon" style="cursor: pointer;" onclick="$('#depositeDate').focus();">
<i class="fas fa-calendar-alt fa-2x"></i>
</div>
</div>
</div>
this code will do:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/css/bootstrap-datetimepicker.min.css">
<br>
<div class="container">
<div class="row">
<div class='col-sm-6'>
<div class="form-group">
<label for="Order number">Order number</label>
<input type="text" id="Order number" >
</div>
<div class="form-group">
<div class='input-group date' id='datetimepicker1'>
<label for="male">Deposit Date</label>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
</div>
<script>$(function() {
$('#datetimepicker1').datetimepicker();
});</script>
check out the fiddle:https://jsfiddle.net/rqy7L2do/
Login form
This is the code for the login form. From the picture it can be seen that the entire textbox isn't highlighted. What am I missing?
<div class="login">
<div class="login-form">
#using (Html.BeginForm("Login", "Account", FormMethod.Post, new { #class = "form-horizontal", role = "form" }))
{
#Html.AntiForgeryToken()
<h2 style="margin-left:-15px">Login</h2>
<div id="maintenance"></div>
<div class="bg-danger text-danger FailureCont">
</div>
<div class="form-group">
<span id="BodyContent_LoginCtrl_UserNameRequired" title="Username is required." class="bg-danger text-danger block" style="visibility:hidden">Username is required.</span>
<div class="input-group login-group">
<span class="input-group-addon">
<i class="fa fa-user"></i>
</span>
<div>#Html.TextBoxFor(m => m.UserName, new { #class = "form-control", placeholder = "Email", aria_required = true })</div>
#*#Html.ValidationMessageFor(m => m.UserName, "", new { #class = "text-danger" })*#
#* <input name="ctl00$BodyContent$LoginCtrl$UserName" type="text" id="BodyContent_LoginCtrl_UserName" tabindex="1" class="form-control" placeholder="Username" autocomplete="off" disabled="disabled" data-validate="placeholder required" />*#
</div>
</div>
<div class="form-group">
<span id="BodyContent_LoginCtrl_PasswordRequired" title="Password is required." class="bg-danger text-danger block" style="visibility:hidden;">Password is required.</span>
<div class="input-group login-group">
<span class="input-group-addon">
<i class="fa fa-lock"></i>
</span>
#*<input name="ctl00$BodyContent$LoginCtrl$Password" type="password" id="BodyContent_LoginCtrl_Password" tabindex="2" class="form-control" placeholder="Password" autocomplete="off" disabled="disabled" data-validate="placeholder required" />*#
#Html.PasswordFor(m => m.Password, new { #class = "form-control", placeholder = "Password" })
</div>
</div>
<div class="form-group">
<div class="col-sm-6 small-side-padding">
<button type="button" class="btn btn-secondary btn-block" id="" onclick="location.href='#Url.Action("Register","Account")'">Register</button>
</div>
<div class="col-sm-6 small-side-padding">
<input type="submit" class="btn btn-primary btn-block" id="bSummit" value="Login" />
#*<input type="submit" name="ctl00$BodyContent$LoginCtrl$LoadingLoginButton" value="Login" id="BodyContent_LoginCtrl_LoadingLoginButton" class="btn btn-primary btn-block hidden"/>*#
</div>
</div>
#*<input type="submit" name="ctl00$BodyContent$LoginCtrl$LoginButton" value="Login" class="btn btn-primary btn-block" />*#
<div class="form-group text-center forgottenCont">
Need help with your <a class="forgottenpwd" href="/Account/ForgotPassword.cshtml">username</a> or <a class="forgottenpwd" href="#Url.Action("ForgotPassword","Account")">password</a>?
</div>
}
</div>
<div class="text-center login-icons hidden-ph">
<i class="fa fa-2x fa-twitter"></i>
<i class="fa fa-2x fa-linkedin"></i>
<i class="fa fa-2x fa-facebook"></i>
</div>
</div>
I'm not sure why the entire textbox isn't highlighted. Can someone please tell me where I'm going wrong. Thank you.
.login-group {
background: #fff;
border: 1px solid #ccc;}
.login-group .form-control {
border: 0;}
#Nimmi: Not sure if any style is overridden here, but thanks :)
I have a form in a modal window :
<div class="modal fade bs-example-modal-lg" id="vp" >
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Create Job</h4>
</div>
<div class="modal-body container-fluid">
<form id="create_job" method="post" action="?create">
<div class="form-group">
<div class="row">
<div class="col-md-4">
<input type="text" class="form-control" placeholder="Job number - Jxxxx" name="job_number">
</div>
<div class="col-md-4">
<input type="text" class="form-control" placeholder="Part number - xxxxxx" name="part_number">
</div>
<div class="col-md-2"><p class="form-control-static text-right"><b>Cable length (m):</b></p></div>
<div class="col-md-2">
<input type="text" class="form-control" placeholder="Cable" value="06" name="cable">
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" name="submitButton" class="btn btn-primary">Submit</button></form>
</div>
</div>
</div>
</div>
This is the validation js:
$(document).ready(function() {
$('#create_vpf_job').formValidation({
framework: 'bootstrap',
excluded: ':disabled',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
job_number: {
validators: {
notEmpty: {
message: ' '
}
}
},
part_number: {
validators: {
notEmpty: {
message: ' '
}
}
},
cable: {
validators: {
notEmpty: {
message: ' '
}
}
}
}
});
});
I've look online for same problems but I haven't found a solution. The submit button doesn't submit. I'm using formvalidation.io for validation and nothing from their docs helped me.
Also tried adding with no luck
$('#create_job').submit();
Your HTML is bad formatted, and the form is closing after the container div closes, so the submit button doesn't know what to submit. Change it to:
<div id="vp" class="modal fade bs-example-modal-lg">
<div role="document" class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 id="myModalLabel" class="modal-title">Create Job</h4>
</div>
<div class="modal-body container-fluid">
<form action="?create" method="post" id="create_job">
<div class="form-group">
<div class="row">
<div class="col-md-4">
<input type="text" name="job_number" placeholder="Job number - Jxxxx" class="form-control" />
</div>
<div class="col-md-4">
<input type="text" name="part_number" placeholder="Part number - xxxxxx" class="form-control" />
</div>
<div class="col-md-2">
<p class="form-control-static text-right">
<b>Cable length (m):</b>
</p>
</div>
<div class="col-md-2">
<input type="text" name="cable" value="06" placeholder="Cable" class="form-control" />
</div>
</div>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">Close</button>
<button class="btn btn-primary" name="submitButton" type="submit">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
And it will work. On this plunkr you can check that it's giving a bad-request response, which is good news, because it means the request is being done, and so, the form is being submitted once the correction made
I'm trying to insert a new branch for distributor data to pass to Sinatra. It's able to insert a new record but this error is produced:
"ERROR Rack::Lint::LintError: body yielded non string value [:disBranchID, 27]"
disBranchID is the primary key of the table and it's set to auto increment.
The HTML looks like this:
<form name="add_dis_branch_form" action="/add_dis_branch" method="post" id="disB" enctype="multipart/form-data">
<div class="input-group">
<span class="input-group-addon"> Brand </span>
<select id="disSlcMan" class="btn btn-default full-width" name="disID" ng-model="disB.disID" required>
<option value="">Select Brand</option>
<% AutoMobile::DB[:distributor].select(:disID, :disComName).each do |dis| %>
<option value="<%= dis[:disID]%>"><%= dis[:disComName] %></option>
<% end %>
</select>
</div>
<br>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-map-marker"></i> Address</span>
<input type="text" class="form-control" name="address" placeholder="Address" required ng-model="disB.address" >
</div>
<br>
<div class="row">
<div class="col-lg-6 col-md-6">
<div class="input-group">
<span class="input-group-addon"> City </span>
<input type="text" class="form-control" name="city" placeholder="Petaling Jaya" required ng-model="disB.city">
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="input-group">
<span class="input-group-addon"> State </span>
<input type="text" class="form-control" name="state" placeholder="Selangor" required ng-model="disB.state">
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-lg-6 col-md-6">
<div class="input-group">
<span class="input-group-addon"> Zip </span>
<input type="text" class="form-control" name="zip" placeholder="47800" required ng-model="disB.zip" ng-pattern="/^\d{5}$/">
</div>
<span ng-show="add_dis_branch_form.zip.$error.pattern" class="help-inline">Invalid zip code</span>
</div>
<div class="col-lg-6 col-md-6">
<div class="input-group">
<span class="input-group-addon" title="Map"><i class="fa fa-map-marker"></i></span>
<button id="btMap" class="btn btn-success form-control" onclick="return false;">Find Your Location</button>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-lg-6 col-md-6">
<div class="input-group">
<span class="input-group-addon"> Latitude </span>
<input type="text" class="form-control" id="disLat" name="latitude" required ng-model="disB.latitude" >
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="input-group">
<span class="input-group-addon"> Longitude </span>
<input type="text" class="form-control" id="disLong" name="longitude" required ng-model="disB.longitude" >
</div>
</div>
</div>
<small>
<b class="help-inline">
Click Find Your Location button to locate your address.
</b>
</small>
<br>
<div class="row">
<div class="col-lg-6 col-md-6">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-phone"></i> Phone</span>
<input type="text" class="form-control" name="phoneNo" placeholder="03-12345432" required ng-model="disB.phoneNo" ng-pattern="/^0[0-9]{1}-[0-9]{8}$/">
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-print"></i> Fax </span>
<input type="text" class="form-control" name="faxNo" placeholder="03-12345432" required ng-model="disB.faxNo" ng-pattern="/^0[0-9]{1}-[0-9]{8}$/">
</div>
</div>
</div>
<br>
<div class="pull-right">
<input type="submit" class="btn btn-success" ng-disabled="!canSave('add_dis_branch_form')">
</div>
</form> <!-- end form -->
The Sinatra code:
add_dis_branch = lambda do
newBranch = AutoMobile::DisBranch.new
newBranch.address = params[:address]
newBranch.city = params[:city]
newBranch.state = params[:state]
newBranch.zip = params[:zip]
newBranch.phone = params[:phoneNo]
newBranch.fax = params[:faxNo]
newBranch.latitude = params[:latitude]
newBranch.longitude = params[:longitude]
newBranch.disID = params[:disID]
newBranch.save
end
Here is one way you could write the route:
post "/automobile/branch" do
newBranch = AutoMobile::DisBranch.new
newBranch.address = params[:address]
newBranch.city = params[:city]
newBranch.state = params[:state]
newBranch.zip = params[:zip]
newBranch.phone = params[:phoneNo]
newBranch.fax = params[:faxNo]
newBranch.latitude = params[:latitude]
newBranch.longitude = params[:longitude]
newBranch.disID = params[:disID]
newBranch.save
halt 201
end
but I suggest you take a good read of the documentation for Sinatra on creating routes and for Sequel on creating model instances.