Why is my ng-pattern in textbox of name is allowing special characters?
This is the view file:
<div ng-repeat="s in config.students">
<div class="form-group">
<label class="control-label col-lg-2"></label>
<div class="col-lg-5">
<input type="text" class="form-control" name="students[]" ng-trim="false" ng-model="class.students[$index]" required ng-pattern="/^[a-zA-Z]*$/">
</div>
<div class="col-md-5">
<button class="btn btn-danger btn-sm" ng-click="removeStudent($index)" type="button">X</button>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2"></label>
<div class="col-lg-4">
<button type="submit" class="btn btn-primary btn-grad btn-rect">Submit</button>
Cancel
</div>
</div>
ng-pattern alone will not prevent a user from entering certain text into a textbox. If you want to do that, you'll need to use a custom attribute directive on the <input>.
ng-pattern is meant to be used in conjunction with AngularJS' form validation, you can use it to hide/show validation messages and to validate a form before it is submitted.
AngularJS form validations requires unique name for each input field in the form.
But in your case you are using the same name for all the input fields in ng-repeat.
So change your input to add unique name for input in each iteration using $index
<input type="text" class="form-control" name="students{{$index}}" ng-trim="false" ng-model="class.students[$index]" required ng-pattern="/^[a-zA-Z]*$/">
Here is the Plunker.
Related
I have no clue where to start with this. Basically, I want the class of a input to change to has-success when a username that is in a database table called Username is equal to the string that the user has written. The current code for the form is:
<div class='container col-md-3 rounded p-5 mt-5 border'>
<form action="Authentication.php" method ="post">
<h3 class='text-center'>Please Login</h3>
<h5 class='pt-3'>Enter Username and Password</h5>
<div class="form-group mb-0">
<input class='form-control float-left mt-3 mb-1' placeholder="Username" type="text" name="username">
<br>
<input class='form-control float-left mb-3' placeholder="Password" type="password" name="password">
<br>
</div>
<div class="text-center">
<input type="submit" class='btn btn-primary btn-sx' value="Login">
</div>
</form>
</div>
So whenever anyone types in the field with placeholder="username" it needs to check whether that string matches with any in the column Username in the table Students and if it does update the class to success.
Thanks so much for the help,
Toby
If the code above is in Authentication.php witch is called by the form, then where you check if $_POST has been submitted, initialize a $extraClass = '';
If (your_condition is true) $extraClass = 'success';
and down there in the form, add an
This way it will keep it empty if the condition si not met.
I have a form with n numbers of data. When I click submit on request ($_REQUEST), I could receive only 1st 50 data.
The form field inputs are in an array. What could be the issue?
Sample code:
<div class="DTE_Field_Type_text DTE_Field_Name_Branch_name Phone">
<label data-dte-e="label" class="col-sm-2 control-label">
Branch Name:
<div data-dte-e="msg-label" class="DTE_Label_Info"></div>
</label>
<div data-dte-e="input" class="col-sm-4">
<input value="" name="branch_name_48[]" placeholder="Branch Name" id="DTE_Field_branch_name_48" class="form-control-occupancy" required="" type="text">
<div style="display: none;" data-dte-e="msg-error" class="help-block"></div>
<div data-dte-e="msg-message" class="help-block"></div>
<div data-dte-e="msg-info" class="help-block"></div>
</div>
<label data-dte-e="label" class="col-sm-2 control-label">
Branch Address:
<div data-dte-e="msg-label" class="DTE_Label_Info"></div>
</label>
<div data-dte-e="input" class="col-sm-4">
<textarea name="branch_addr_48[]" placeholder="Branch Address" id="DTE_Field_hq_addr_48" class="form-control-occupancy"></textarea>
<div style="display: none;" data-dte-e="msg-error" class="help-block"></div>
<div data-dte-e="msg-message" class="help-block"></div>
<div data-dte-e="msg-info" class="help-block"></div>
</div>
</div>
<input class="btn btn-primary" id="savenext" name="save" value="Save" type="submit">
The form has more fields, i.e branch_addr_100 and so on. From this form, I could receive only branch_addr_49. How could I retrieve all 100 records?
I have shown the data from db and shown in the form where the div's on load are collapsed and given display:none to avoid too much data on the page load.when needed the div's can be expanded.Will that be a problem
I think the issue is, limit of max_input_vars exceeds in your case.
There a limit to the maximum number of form elements in (one nesting level) like it is controlled by the php.ini directive max_input_vars. So you have to increase that limit to get all values.
here is my html
<form name="station" method="post" action="/stations/new" role="form">
<div class="form-group">
<label class="control-label required" for="station_name">Name</label>
<input type="text" id="station_name" name="station[name]" required="required" maxlength="255" class="form-control" >
</div>
<div class="form-group">
<div class="checkbox">
<label for="station_active">
<input type="checkbox" id="station_active" name="station[active]" value="1" />Active</label>
</div>
</div>
<div class="form-group">
<button type="submit" id="station_submit" name="station[submit]" class="btn btn-primary">Ajouter</button>
</div>
<input type="hidden" id="station__token" name="station[_token]" class="form-control" value="aze123aze" >
</form>
i want to get my form using the crawler. I tried the selectButton method like this
$form = $crawler->selectButton('station[submit]')->form(array());
but i get the error : InvalidArgumentException: The current node list is empty.
what is the problem ?
Unfortunately I have no enough rating to just write a comment instead of put it in the answer.
So, could you please show how are you getting $crawler? Problem might be:
$crawler not point to DOM which contains this form
this form appears on page after some java script actions(Ajax for example), but not sure that this is your case.
The selectButton method accept the value The button text. So Try with:
$form = $crawler->selectButton('Ajouter')->form(array());
Hope this help
I am newbie in laravel and I try to insert a data form a form having foreign key by using hide such as the code is mention below:-
<form class="form-horizontal" role="form" action="/WhatTodo/store" method="POST">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="task_id" value=" {{$what->task_id}}">
<input type="hidden" name="work_id" value="{{$what->work_id}}">
<div class="form-group">
<label class="control-label col-sm-2" for="name"> Name</label>
<div class="col-sm-5">
{!!Form::select('name',$name)!!}
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="work">work:</label>
<div class="col-sm-5">
<input type="text" class="form-control" name="work" value="">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-default" value="Submit">
</div>
</div>
</form>
I have the controller with function:-
public function create($id)
{
$what=WhatTodoModel::findorFail($id);
$name=WOrk::lists('name','name');
return view('what/create',compact('what','name'));
}
You haven't really told us what your issue is or what error you're getting, but my guess given the current question is:
Assuming you're trying to implement a resource route and resourceful controller, the create method is used to show a form to create a new object, not edit an existing one. The create method does not take any parameters, therefore $id will be blank and WhatTodoModel::findorFail($id); will throw an exception.
If you want to edit an existing record, you do that using the edit action.
For creating a new record, create shows the form, store saves the record.
For editing an existing record, edit shows the form, update saves the record.
I have some portlets here that has an ID for each of it. What I'm trying to do is to pass these IDs to a popup modal after pressing an Add button in the portlet.
Here is the portlet view:
#foreach($portlets as $portlet)
<div class="box span4">
<div class="box-header well" data-original-title>
<h2><i class="icon-th"></i> {{$portlet->portlet_title}} </h2>
</div>
<div class="box-content">
<div class="row-fluid">
// some contents over here
</div>
<div class="box-icon">
<i class="icon-plus-sign"></i>
</div>
</div>
</div>
#endforeach
Notice the Add New Link button at the bottom of the code, when I press that, a modal will appear. Here is the view of it:
<div class="modal hide fade" id="linkSettings">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Add New Link</h3>
</div>
<form method="post" action="{{ URL::to('addlink') }}" >
<div class="modal-body">
<div class="control-group">
<label class="control-label" for="focusedInput">Link Title:</label>
<div class="controls">
<input class="input-xlarge focused" id="link_title" name="link_title" type="text">
</div>
</div>
<div class="control-group">
<label class="control-label" for="focusedInput">Add A Link:</label>
<div class="controls">
<input class="input-xlarge focused" id="link_url" name="link_url" placeholder="eg. http://www.example.com/" type="text">
</div>
</div>
</div>
<div class="modal-footer">
Close
<input type="submit" id="submit" name="submit" value="Submit" class="btn btn-primary">
</div>
</form>
</div>
This modal has a form in it to be processed in the controller. But how do I send the portlet ID to this modal so that it can be stored in the database during processing in the controller? Because I want it to automatically know what portlet I want to add links in it. Any idea?
If anything, please let me know.
You could attach a jQuery event handler to clicking the "Add New Link" button, and use it to populate a hidden field in the modal view.
i.e. something like:
$("a.new_link").click(function(){
portlet_id = $(this).parent().parent().attr("id");
$("div.modal form input.my_hidden_field").val(portlet_id)
});
And somewhere in the <form> for the modal:
<input type="hidden" name="portlet_id" class="my_hidden_field"/>
Then, you just need to get the portlet_id POST parameter with Laravel/PHP to determine the portlet ID that was used.
Edit
Revised handler based on the code you gave:
$('.btn-settingLink').click(function(e){
e.preventDefault();
$('#linkSettings').modal('show');
// get the portlet_id and modify the midden field
portlet_id = $(this).parent().parent().attr("id");
$("div.modal form input.my_hidden_field").val(portlet_id)
});