I have an AngularJs dropdown in witch i set a value selected based on some conditions.
The dropdown work as it should but the only problem is that, if i don't do any action on it, if i submit the form, i wont receive the default value that was selected dinamically.
<!-- Payment Page -->
<div class="form-group">
<label class="control-label">Payment Page *</label>
<select name="payment_page" class="form-control" ng-model="invoice_data.form_data.payment_page">
<option ng-repeat="p_page in invoice_data.data.payment_pages" value="{{ p_page.id }}" ng-selected="(p_page.id === invoice_data.form_data.payment_page || p_page.default)">
{{ p_page.name }}
</option>
</select>
</div>
<!-- /End Payment Page -->
In the inspect element, the dropdown looks good, the option has it's value and so on but, after submitting the form i don't receive the selected value.
If i change, the dropdown selection and submit the form, i receive the value but as for default one no.
I do not know about php. But i can guess, This is because when your drop-down stays untouched ngModel does not get any value. For that when you submit your form you does not get default value. For solution :
You can do 2 way at controller or at html:
1) At html use ng-init directive for initialize ng model to default value.
ng-init="invoice_data.form_data.payment_page = p_page.default ">
2)At controller when your form submit check for null value in ngModel or untouched of select dropdown, if it is null then add your default value.
Thanks Jenny for your time and response...
I have done this way in controller:
angular.forEach(response.data.payment_pages, function(value, key) {
if (value.default) {
$scope.invoice_data.form_data.payment_page = value.id;
}
});
Related
I'm having a trouble on how can I check the radio button when the v-models is empty, . If the value of my formfields.status is empty the radio button should automatically checked. Is there anyway trick how to implement it?
This is status value looks like in my dev tools extension when status value is empty
This is what I've tried but nothing works, thanks in advance!.
<div class="checkbox-inline">
<label class="radio mr-2">
<input class="details-input" type="radio" name="status_radio" value="1" v-model="formFields.status" :checked="formFields.status == null"/> Active
</label>
<label class="radio">
<input class="details-input" type="radio" name="status_radio" value="0" v-model="formFields.status"/> Inactive
</label>
</div>
V-model is working with the checked property of radio buttons, so setting that on your own as well might result in faulty behaviour.
When you're using V-model, you'd expect the UI to be always in sync with the data. Note that the "empty selection" state is invalid for radio buttons, there should be one always selected. If you wanted to allow empty selection using an optional select field would be better from UX perspective as well.
So, the easiest way to fix it is disallowing the empty state for your model by providing a default value to the status field, which would control which radio button should be checked by default.
In short:
use "status: 1" in your data to set the default value
remove the :checked bindings from the template
I'm trying to return the value of a checkbox within my laravel controller, but every time I request a input from a checkbox element in a form, it returns null.
My controller, retrieving the input of a element called Filter-Method.
Here I'm trying to request a input method called filter-method which is a checkbox.
My Route, since this function will execute on a button:
My Blade, where I'm trying to retrieve the result of my filter-method checkbox:
On line 38 I have a checkbox called filter-method, and when you click on the button on line 115 it should send a request to the controller where it would return a result but instead it returns null
Any ideas of why I'm returning null?
You are not passing any parameter named filter-method. If you are posting values you should use post method.
Like following
Route::post('GetFilterByColumns','MentorController#FilterByValuesColoumns')
If you want to list data according to filter-method then try the following.
Route::get('GetFilterByColumns/{filter-method}','MentorController#FilterByValuesColoumns')
And in your mentorlist.blade.php page
change the href value according to route.
You have to add form to your blade around checkbox either with get or post method as per your requirement change route according to your form method
consider demo blade file
<form method="get" action="{{ url('GetFilterByColumns') }}" class="form-horizontal form-label-left" id="">
<div class="checkbox">
<label><input type="checkbox" name="filter-method" value="filter-method>Method</label>
</div>
<input type="submit" value="submit"/>
</form>
Now you will get a checkbox value in contoller
This is very basic thing just use form instead of <a> tag. Every time you need to send input value to server you need to use <form> element. In image you have uploaded there is no <form> and you are using a <a> tag.
You need to do it like this
<form method="get" action="/getFilterBycolumns">
<input type="checkbox" name="filter-method">
// other input fields
// and then a submit button instead of <a>
<button class="your-class" type="submit"> Send</button>
just use POST instead of GET if you are sending form values
I have two pages lets say first.php, second.php.
first.php:
<form name=register method="post" action="second.php">
Name:<input type="text" name="username" value=<?=$username?> >
Email:<input type="email" name="email" value=<?=$email?> >
Hobbies:<select name="hobbies" id="hobbies" disabled>
<option value="cricket">cricket</option>
<option value="football">football</option>
</select>
</form>
second.php:
<?
print_r($_POST);
I am getting only name and email and not select value.
If I print the post value I am not getting the select value, but when I am removing the disabled in select, I am getting the select value in hidden.
In this scenario, I don't want the user to select the select box and when I submit the form, I should get the value in hidden in second.php.
I have tried many possible ways, to no avail.
Can anybody suggest me how can I achieve this.
Disabled tags can't be send to POST. Change disabled to readonly or hidden
You cant post a disabled field. Maybe you can disable the selectbox right before you post it or you could (like the comments tell you) get a hidden value to be posted that has the standard value you want. If the select box is able to be posted(so not disabled) you can overwrite the hidden value with the select value.
You can do this by Jquery before the form is submitted.
<script>
$(document).ready(function () {
$('#register').submit(function() {
$('select').removeAttr('disabled');
});
});
</script>
In
second.php
you have to create a validation to check that user can be registered or no.
if($this->user->can_register()){
$this->user->save($_POST['hobbies']);
}
Because if only with html or js exception is not enough to handle that case. Some users can just inspect element and remove the disabled element.
I'm building an app using Laravel and Twitter Bootstrap. And now i've come to a point i where want to use checkboxes. Bootstrap styles the checkboxes automatically which is nice.
But in PHP i can't get the value of the checkbox to determine whether it's checked. Bootstrap seems to use "uniform" to style the checkbox. When i exclude that file i CAN get the value of the checkbox.
I do this to get the value:
$checkbox = Input::get('checkbox', function() {return 0;});
If the input has a value, use the value, else return 0.
It works fine, except when Bootstrap styles the checkbox. With jQuery it's possible to check if the span of the checkbox has the class "checked" but I want to check server-side. But Bootstrap/Uniform doesn't apply "checked" to the checkbox itself.
Are there more people that have the same problem? Or even better, does someone have the solution for this? Thanks!
On form submittal you can always check for the validation of the checkbox:
PHP Code:
<?php if(isset($_POST['$yourName'])){}; ?>
HTML Code:
<div class="form-group input-group-sm">
<label class="col-md-4 control-label" for="$yourName">Your Title</label>
<div class="col-md-1 input-group-sm">
<input id="$yourName" name="$yourName" type="checkbox" class="form-control">
</div>
</div>
<select class="txtbx1" name="country" disabled>
<option value='FR' >FRANCE</option><option value='CH' selected>SWITZERLAND</option>
</select>
the above code is inside a form whose method is post
but echo $_POST['country'] is showing nothing.. on the other hand if I remove disabled from select $_POST['country'] is showing the correct result
This is how the disabled attribute works. When a form control is disabled, the value will be ignored when the form is submitted and the key will not be present in $_POST (or $_GET).
If you want the value to be present in the submitted data, but you don't want the user to be able to change the value on the page (which I imagine is what you are trying to acheive) use readonly="readonly" instead of disabled="disabled".
EDIT
The <select> element does not have a readonly attribute. The above information still stands as it will work for <input>s and <textarea>s.
The solution to your problem here would be to disable the select and use a hidden input to send the value back to the server - e.g.
When the select is enabled:
<select class="txtbx1" name="country">
<!-- options here -->
</select>
...and when it is disabled:
<select class="txtbx1" name="country_disabled" disabled="disabled">
<!-- options here, with appropriate value having `selected="selected"` -->
</select>
<input type="hidden" name="country" value="value_of_field" />
This is the correct behavior. disabled disables the element, and does not send it's value when a form is POSTed.
You can use JavaScript to un-disable the form before you submit it. Something like this (untested):
document.getElementById('myForm').addEventListener('submit', function() {
for(var i = 0; i < this.children.length; i++){
var child = this.children[i];
if(child.disabled){
child.disabled = false;
}
}
});
How your form tag looks like? You may have forgotten the method="post" attribute...
If your goal is have a "readonly select" - that is show the user what the choices are without allowing it to change and have it sent with the POST variables, you want to use "selected" on the option with the current value, and "disabled" on all the other options. This will essentially show the select with all its options but only allow the current one to be selected.
I find this more helpful than simply having a disabled select.
As others have noted, you still need to insure that the server side doesn't accept changes to the field (as with any readonly field).