How to submit form with partially read only inputs with jQuery? - javascript

I made a form in jQuery + Django which has only one input active and the others are read only. There is a button which when clicked activates all the input boxes and the whole form is then editable. However, before clicking the button only one input is there and I want to be able to submit the form in that state. But I want all the other values to be submitted too, as they are readonly that should not be a problem.
Here's my JS:
$('#addInventoryForm').on('submit', function(event) {
event.preventDefault();
$('#name').focus();
add_to_inventory();
});
function add_to_inventory() {
console.log("add to inventory is working!")
$.ajax({
url : "/new/item/add/",
type : "POST",
data : { upc : $('#upc').val(), name : $('#name').val(), qty : $('#qty').val(), add_qty : $('#add_qty').val(), reorder_qty : $('#reorder_qty').val(), dp : $('#dp').val(), mrp : $('#mrp').val(), supplier : $('#supplier').val() },
success : function(data) {
console.log(data);
$('#extra').html(data);
console.log("success");
}
});
}
The url in the above code points to the following view:
def NewItemAdd(request):
if request.method == "POST":
upc = request.POST['upc']
name = request.POST['name']
if 'qty' in request.POST:
qty = request.POST['qty']
add_qty = request.POST['add_qty']
reorder_qty = request.POST['reorder_qty']
dp = request.POST['dp']
mrp = request.POST['mrp']
if 'supplier' in request.POST:
supplier = Supplier.objects.get(name=request.POST['supplier'])
if 'qty' not in request.POST:
qty = 0
if 'supplier' in request.POST:
defaults = {'name': name, 'qty': int(qty) + int(add_qty), 'reorder_qty': reorder_qty, 'dp': dp, 'mrp': mrp, 'supplier': supplier, 'user': request.user}
else:
defaults = {'name': name, 'qty': int(qty) + int(add_qty), 'reorder_qty': reorder_qty, 'dp': dp, 'mrp': mrp, 'user': request.user}
inv, created = Item.objects.update_or_create(upc=upc, defaults=defaults)
supplier_list = Supplier.objects.all()
return render(request, "alpha/new-item-add.html", {'suppliers': supplier_list})
The template used with this view is as follows:
<div class="container">
<div class="form-group">
<label class="control-label col-xs-1" for="name">Name:</label>
<div class="col-xs-9">
<input type="text" class="form-control" id="name" name="name" placeholder="" tabindex="2"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-1" for="qty">Current Quantity:</label>
<div class="col-xs-2">
<input type="number" class="form-control" id="qty" name="qty" placeholder="" readonly/>
</div>
<label class="control-label col-xs-1" for="add_qty">Add Quantity:</label>
<div class="col-xs-2">
<input type="number" class="form-control" id="add_qty" name="add_qty" placeholder="" tabindex="3"/>
</div>
<label class="control-label col-xs-offset-1 col-xs-1" for="reorder_qty">Reorder Quantity:</label>
<div class="col-xs-2">
<input type="number" class="form-control" id="reorder_qty" name="reorder_qty" placeholder="" tabindex="4"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-1" for="dp">DP:</label>
<div class="col-xs-2">
<input type="text" class="form-control" id="dp" name="dp" placeholder="" tabindex="5"/>
</div>
<label class="control-label col-xs-1" for="mrp">MRP:</label>
<div class="col-xs-2">
<input type="text" class="form-control" id="mrp" name="mrp" placeholder="" tabindex="6"/>
</div>
<label class="control-label col-xs-offset-1 col-xs-1" for="reorder_qty">Supplier:</label>
<div class="col-xs-2">
<select name="supplier" id="supplier" class="btn btn-default form-control" tabindex="7">
{% for supplier in suppliers %}
<option value="{{ supplier }}" {% if supplier.name == item.supplier.name %}selected{% endif %}>{{ supplier.name }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-1 col-xs-9">
<input type="submit" value="Submit" class="form-control btn btn-primary" tabindex="8"/>
</div>
</div>
</div>
I want to be able to submit the form when the inputs are readonly as well as when I click a button and activate all the inputs. Can anyone find anything wrong with the above code?

The edit button removes the readonly attribute from all the inputs of the form. So before submitting the form I trigger a click on the edit button. It's almost instantaneous and the problem is solved.
$("#edit").trigger("click");

Related

jQuery Cloning and incrementing input, textarea, that has name, id and for

I'm still very new to jQuery, and would need help to how to increment 3 elements in this code.
name, id & for.
The name consist of products[0]category, id consist of checkbox[0], for consist of checkbox[0] which is for labels on the checkbox that id use.
I've tried searching for examples. But all them haven't found any good results that i could learn from unfortunately. So in the codes below, they're not there to increase increment as i have totally no idea what else i can do to increase increment numbering.
$(document).ready(function() {
let $append = $('#append');
// append location's data listing
$append.on('change', '.location', function(){
var value = $(this).val();
$('.location_id').val($('#locations [value="'+value+'"]').data('locationid'));
$('.loc_desc').val($('#locations [value="'+value+'"]').data('locdesc'));
});
// enable checkbox for serialnumbers
$append.on('change','.enable-serial', function(){
let $item = $(this).closest('.product-item');
let $checkbox = $item.find('.enable');
$checkbox.prop('disabled', !this.checked);
});
// ctrl for key in checkbox
$append.on('click', '.keyin-ctrl', function() {
let $container = $(this).closest('.product-item');
let $serial = $container.find('.serial');
$container.find('.display').val(function(i, v) {
return v + $serial.val() + ';\n';
});
$serial.val('').focus();
});
// ctrl for del textarea
$append.on('click', '.undo-ctrl', function() {
let $container = $(this).closest('.product-item');
$container.find('.display').val('');
});
// clone product, increment products[x]var
$('#add_product').on('click', function() {
var itemNo = $('.product-item').length + 1;
var index = $('.product-item').length;
var regex = /^(.+?)(\d+)$/i;
let $product = $append.find('.product-item.template')
.clone()
.show()
.removeClass('template')
.insertAfter('.product-item:last');;
$product.find('span').text('#' + itemNo);
$product.find(':checkbox').prop('checked', false);
$product.find('.enable').prop('disabled', true);
$product.find('input, textarea').val('');
$('#append').append($product);
});
// delete product, but remain original template intact
$('#delete_product').on('click', function(){
var itemNo = $('.product-item').length + 1;
let $product = $append.find('.product-item:last:not(".template")');
$product.remove();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<main class="shadow border">
<h4>{{ __('Product Details') }}</h4>
<hr>
<form method="post" action="">
<!-- Multiple Product addition -->
<div class="form-group row">
<label class="col-sm-2 col-form-label font-weight-bold">{{ __('Product Setting') }}</label><br/>
<div class="col-sm-5">
<button type="button" id="add_product" class="btn btn-dark">{{ __('Add Product') }} <i class="fas fa-plus-square"></i></button>
<button type="button" id="delete_product" class="btn btn-dark ml-3">{{ __('Delete Last Product') }} <i class="fas fa-minus-square"></i></button>
</div>
</div>
<hr>
<!-- Frist Group -->
<div class="product" id="append">
<!-- Product Details -->
<div class="product-item template">
<span>#1</span>
<div class="form-group row">
<label class="col-sm-2 col-form-label font-weight-bold">{{ __('Category') }}</label>
<div class="col-sm-2">
<input class="form-control" name="products[0]category" type="text" placeholder="eg. 333" maxlength="3"required>
</div>
<label class="col-sm-1 col-form-label font-weight-bold">{{ __('Code') }}</label>
<div class="col-sm-2">
<input class="form-control" name="products[0]code" type="text" placeholder="eg. 22" maxlength="2" required>
</div>
<label class="col-sm-1 col-form-label font-weight-bold">{{ __('Partnumber') }}</label>
<div class="col-sm-2">
<input class="form-control" name="products[0]partnumber" type="text" placeholder="eg. NGH92838" required>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label font-weight-bold">{{ __('Brand') }}</label>
<div class="col-sm-2">
<input class="form-control" name="products[0]brand" type="text" placeholder="eg. Rototype" required>
</div>
<label class="col-sm-1 col-form-label font-weight-bold">{{ __('Quantities') }}</label>
<div class="col-sm-2">
<input class="form-control" name="products[0]qty" type="number" placeholder="eg. 1" required>
</div>
<label class="col-sm-1 col-form-label font-weight-bold">{{ __("Location") }}</label>
<div class="col-sm-2">
<input class="form-control location" type="text" name="products[0]loc_name" list="locations" value="">
<input type="hidden" class="location_id" name="products[0]location_id" value="">
<input type="hidden" class="loc_desc" name="products[0]loc_desc" value="">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label font-weight-bold">{{ __("Description") }}</label>
<div class="col-sm-8">
<input class="form-control" name="products[0]description" type="text" placeholder="eg. Spare part for CSD2002">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label font-weight-bold">{{ __('Seial Number(s)') }}</label>
<div class="col-sm-5">
<input class="form-control enable serial" maxlength="25" placeholder="Key in Serial Number and hit button 'Key In'" disabled>
</div>
<div class="col-sm-5">
<button class="btn btn-dark enable keyin-ctrl" type="button" disabled>{{ __('Key In') }}</button>
<button class="btn btn-dark enable undo-ctrl" type="button" disabled>{{ __('Del') }}</button>
<input class="form-check-input ml-4 mt-2 pointer enable-serial" id="checkbox[0]" type="checkbox">
<label class="form-check-label ml-5 pointer" for="checkbox[0]">{{ __('tick to enable serialnumber')}}</label>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label"></label>
<div class="col-sm-5">
<textarea class="form-control display" name="products[0]serialnumbers" rows="5" style="resize: none;" placeholder="eg. SGH8484848" readonly></textarea>
</div>
</div>
<hr>
</div>
<!-- append start -->
</div>
<div class="form-group row">
<div class="col-sm-12 ">
#csrf
<button type="submit" class="btn btn-dark float-right ml-4">Next <i class="fas fa-caret-right"></i></button>
<!--<button type="button" class="btn btn-secondary float-right" onclick="history.back()">Previous</button>-->
</div>
</div>
<datalist id="locations">
#foreach($locations as $location)
<option value="{{ $location->loc_name}}" data-locationid="{{ $location->location_id }}" data-locdesc="{{ $location->loc_desc }}"></option>
#endforeach
</datalist>
</form>
</div>
</main>
So how do I actually achieve this to add increment to the NAME, ID and FOR my clones?
From the original template of products[0]variable to products[1]variable, checkbox[0] to checkbox[1]
If you want to increment either an ID, class, etc. you can't use .clone(), like the documentation warns:
Using .clone() has the side-effect of producing elements with
duplicate id attributes, which are supposed to be unique. Where
possible, it is recommended to avoid cloning elements with this
attribute or using class attributes as identifiers instead.
You'll have to do it "manually", following a very simple example below:
$( "#addrow" ).click(function() {
var count = $("#product").children().length;
$("#product").append("<input id='field[" + count + "]' type='text'>");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="product">
</div>
<input id="addrow" type="button" value="Add field">

laravel-Auto increment Id

How to get auto increment Id?I created the database.It has customer registration form.Customer Id is auto-generated in DB.I want to fill Id input field by a max value of Id column.ex:
my source code(register.blade.php)
#extends('layerout.registration')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<form action="/insert" method="post">
<center><font color="white"><h2>Registration form</h2></font></center>
<div class="form-group">
{{csrf_field() }}
<script type="text/javascript">
<label for="example-number-input" class="col-2 col-form-label">ID</label>
<input class="form-control" type="number" value="1" name="id">
</script>
<label for="example-text-input" class="col-2 col-form-label">Name</label>
<input class="form-control" type="text" value="name" name="Name">
<label for="example-text-input" class="col-2 col-form-label">Job_titleID</label>
<select class="form-control" type="text" value="0" name="Job_ID"> <option>-0-</option>
#foreach($register as $cat)
<option value="{{$cat->Job_ID}}" name="Job_ID">{{$cat->Job_ID}}</option>
#endforeach
</select>
<label for="example-text-input" class="col-2 col-form-label">Identifier</label>
<input class="form-control" type="text" value="93xxxxxxV" name="Identifier">
<label for="example-text-input" class="col-2 col-form-label">Street</label>
<input class="form-control" type="text" value="Panagoda road" name="Road">
<label for="example-text-input" class="col-2 col-form-label">city</label>
<input class="form-control" type="text" value="Rakwana" name="City">
<label for="example-text-input" class="col-2 col-form-label">Postal Code</label>
<input class="form-control" type="text" value="7000" name="P_code">
<label for="example-text-input" class="col-2 col-form-label">Countery</label>
<input class="form-control" type="text" value="Sri Lanaka" name="Address">
<label for="example-email-input" class="col-2 col-form-label">Email</label>
<input class="form-control" type="email" value="mithika.hetti#gmail.com" name="email">
<label for="example-tel-input" class="col-2 col-form-label">Telephone</label>
<input class="form-control" type="tel" value="+94 071 172 6818" name="tel">
<label for="example-datetime-local-input" class="col-2 col-form-label">Date and time</label>
<input class="form-control" type="datetime-local" value="2011-08-19T13:45:00" name="datetime-local">
<br>
<br>
<button type="Submit" name="Submit" value="Add" id="add" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div>
#endsection
my controller
<?php namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Job_ID;
class register extends Controller{
public function register()
{
$register=Job_ID::all();
return view('cutomer.register',['register' => $register]);
}
function insert(Request $req)
{
$ID=$req->input('ID');
$Name=$req->input('Name');
$Job_ID=$req->input('Job_ID');
$Identifier=$req->input('Identifier');
$Road=$req->input('Road');
$City=$req->input('City');
$P_code=$req->input('P_code');
$Address=$req->input('Address');
$email=$req->input('email');
$tel=$req->input('tel');
$datetimelocal=$req->input('datetime-local');
$data = array('E_ID'=>$ID,"E_Name"=>$Name,"Job_ID"=>$Job_ID,"E_Phone"=>$Identifier,"Road" =>$Road,"City" =>$City,"P_Code" =>$P_code,"E_Address" =>$Address,"E_email"=>$email,"E_Phone" =>$tel,"Date"=>$datetimelocal);
DB::table('employer')->insert($data);
}
}
I created ID column and set auto increment it in Mysql.I want to display max value(4) on Id text-field of customer registration form.
with mysql you can do this
SELECT AUTO_INCREMENT
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = "databaseName"
AND TABLE_NAME = "tableName"
for laravel
$table = DB::select("SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'databaseName' AND TABLE_NAME = 'tableName'");
if (!empty($table)) { echo $table[0]->AUTO_INCREMENT; }
If you are asking how to show the id of a Model, first in your controller, make a collection query like:
$posts= Post::all();
return view(view.post)->withPosts($posts);
and then on your blade file, make a foreach to iterate through all the posts:
#foreach ($postsas $post)
<p>This is ID number {{ $post->id }}</p>
#endforeach
If you are asking how to manually auto increment a certain column, this is the code I used to manually make an auto-increment column (form_counter) starting with value of 1. Basically, I check if there is an existing record, if there is none, the first record for the form_counter column is 1. If it is existing, add 1 to the most current value in the column.
$lastValueCollection = Post::where('formId', $request->inputFormId)->orderBy('Term', 'desc')->first();
$form_counter = 1;
if(isset($lastValueCollection->form_counter)){
$form_counter = $lastValueCollection->form_counter + 1;
}
$data = array('E_ID'=>$ID,....., 'Client_ID'=>$form_counter);
DB::table('employer')->insert($data);
This is not exact but I hope this gives you an idea.
on your schema builder: $table->increments('yourPrimaryKey');
example :
Schema::table('users', function (Blueprint $table) {
$table->increments('id');
});
See the the docs: https://laravel.com/docs/5.5/migrations

laravel 5.4: how to pass value from javascript to controller for updating data

I am new to laravel. I want to update a database row. For this purpose, i want to pass the id of the corresponding row to the controller from javascript. I can get the id in javascript file from view. But i get an error ( ErrorException in PatientController.php line 80: Creating default object from empty value) while doing this. Because controller does not get that id. How can i pass the id and resolve this problem?
my view (editPatientView.blade.php):
<div class="patient-form-view" data-patientid="{{ $patient->id }}">
<h2>Patient Details</h2>
<form action="{{ route('savepatientinfo') }}" method="post"> {{-- route('postCreate') --}}
<div class="form-group">
<label for="name">Name *</label>
<input class="form-control" id="patient_name" name="patient_name" type="text" value="" id="example-text-input">
</div>
<div class="col-md-6" style="float: left; width: 100%; padding-left: 0px">
<div class="form-group" style="float: left; width: 48%; ">
<label for="age">Age *</label>
<input class="form-control" id="patient_age" name="patient_age" type="text" value="">
</div>
<div class="form-group" style="float: left; width: 48%; margin-left: 22.5px;">
<label for="weight">Weight</label>
<input class="form-control" id="patient_weight" name="patient_weight" type="text" value="">
</div>
</div>
<div class="form-group">
<label for="symptom">Symptoms *</label>
<textarea class="form-control" name="symptom" id="exampleTextarea" rows="3" value="{{ $patient->symptom }}"></textarea>
</div>
<div class="form-group">
<label for="test">Tests (if any)</label>
<textarea class="form-control" name="test" id="exampleTextarea" rows="3" value="{{ $patient->test }}"></textarea>
</div>
<div class="form-group">
<label for="Medicine">Medicine</label>
<textarea class="form-control" name="medicine" id="exampleTextarea" rows="3"></textarea>
</div>
<div class="form-group">
<label for="return-date" class="col-2 col-form-label">Return Date</label>
<input class="form-control" name="return-date" type="date" value="{{ $patient->return_date }}" id="example-date-input">
</div>
<button type="submit" class="btn btn-primary" id="edit">Save</button>
<input type="hidden" name="_token" value="{{ Session::token() }}">
</form>
</div>
<script>
var urlEdit = '{{ route('savepatientinfo') }}';
var token = '{{ Session:: token() }}';
</script>
my script (script.js):
var patientId = 0;
$('#edit').on('click', function (event) {
patientId = event.target.parentNode.parentNode.dataset['patientid'];
alert(patientId);
$.ajax({
method: 'POST',
url : urlEdit,
data: {
patientId: patientId,
_token: token
}
});
});
my route:
Route::post('/savepatientinfo', [
'uses'=> 'PatientController#SavePatientInfo',
'as'=>'savepatientinfo'
]);
my controller():
public function SavePatientInfo(HttpRequest $request)
{
// validation...
$this->validate($request, [
'patient_name'=> 'required|max:2000',
'patient_age'=> 'required',
'symptom'=> 'required',
]);
$patient = Patient::find($request['patientId']) ;
// dd($patient);
$user = Auth::user();
$patient->name = $request['patient_name'];
$patient->age = $request['patient_age'];
$patient->weight = $request['patient_weight'];
$patient->symptom = $request['symptom'];
$patient->test = $request['test'];
$patient->return_date = $request['return-date'];
$patient->user()->associate($user);
$patient->update();
if($request->user()->patients()->save($patient))
{
$message = 'Patient information enrolled successfully' ;
}
return redirect()->route('showpatientinfo', ['user_id'=> $patient->user->id, 'patient_id'=>$patient->id])->with(['message'=>$message]);
}

Data From Svc Not Modeling Into View Elements AngularJS

I have a view that is modeled to functions which pass data through to a database. This is all working and I see the data coming back when called, but it is not pre-populating the fields in my view when it comes back. I've been banging my head for a while on this. Everything is modeled (from what I can tell) properly.
I have stepped through the JS code below in Chrome and see the data being assigned to my $scope variables from the data.XXX return.
But, after load finishes, it's not preselecting my radio button or populating the fields with the data. Any help greatly appreciated.
Here is the View:
<div class="notification-container">
<form name="notificationForm" class="form-horizontal" ng-submit="saveQrNotifications()">
<div class="list-unstyled">
<input id="text" ng-model="NotificationMethods.NotificationMethodId" ng-change="notifyVisible()" name="text" type="radio" ng-value="1001"> Text Message<br>
<input id="email" ng-model="NotificationMethods.NotificationMethodId" ng-change="notifyVisible()" name="email" type="radio" ng-value="6"> Email<br>
<input id="voice" ng-model="NotificationMethods.NotificationMethodId" ng-change="notifyVisible()" name="voice" type="radio" ng-value="1003"> Voice<br>
<input id="nocontact" ng-model="NotificationMethods.NotificationMethodId" ng-change="notifyVisible()" name="nocontact" type="radio" ng-value="1000"> Do Not Contact<br>
</div>
<div class="col-md-12 notification-fields" ng-show="notifyFieldVisibility == true">
<div class="col-md-12" ng-if="NotificationMethods.NotificationMethodId == '1001'">
<label class="notication-input">Text Number</label>
<span class="clearfix"></span>
<input class="form-control area-code" type="text" ng-model="NotificationMethods.NotificationTextAreaCode" placeholder="(555)" required>
<input class="form-control phone-number" type="text" ng-model="NotificationMethods.NotificationTextPhoneNumber" placeholder="555-5555" required>
</div>
<div class="col-md-12" ng-if="NotificationMethods.NotificationMethodId == '6'">
<label class="notification-input" for="email">E-mail Address
<input class="form-control" id="email" name="email" type="text" ng-model="NotificationMethods.NotificationEmailAddress" placeholder="ex.me#example.com" required>
</label>
</div>
<div class="col-md-12" ng-if="NotificationMethods.NotificationMethodId == '1003'">
<label class="notication-input">Voice Number </label>
<span class="clearfix"></span>
<input class="form-control area-code" type="text" ng-model="NotificationMethods.NotificationVoiceAreaCode" placeholder="(555)" required>
<input class="form-control phone-number" type="text" ng-model="NotificationMethods.NotificationVoicePhoneNumber" placeholder="555.5555" required>
<label class="small">Ext.</label>
<input class="form-control extension" type="text" ng-model="NotificationMethods.NotificationVoiceExtension" placeholder="555">
</div>
<span class="clearfix"></span>
<div ng-show="notifyLoading" class="text-center" style="margin-top: 10px;">
<i class="fa fa-spinner fa-spin"></i> Saving...
</div>
<div class="col-md-12">
<button type="submit" class="btn btn-primary notification-btn">Save Notifications</button>
</div>
</div>
</form>
</div>
Here is my controller:
DATA COMING FROM DB:
if (data.StatusCode == "SUCCESS") {
$scope.refill = data;
//$scope.deliverTypes = data.DeliveryTypes;
$scope.showError = false;
$scope.submitRefill = true;
$scope.findRefillStatus = userMessageService.QuickRefillMessage(data.Prescriptions[0]);
$scope.isRefillable = data.Prescriptions[0].IsRefillable;
$scope.prescription.noPrescription.$valid = true;
$scope.loading = false;
$scope.NotificationMethods.NotificationEmailAddress = data.NotificationEmailAddress;
$scope.NotificationMethods.NotificationMethodId = data.NotificationMethodId;
$scope.NotificationMethods.NotificationTextAreaCode = data.NotificationTextAreaCode;
$scope.NotificationMethods.NotificationTextPhoneNumber = data.NotificationTextPhoneNumber;
$scope.NotificationMethods.NotificationVoiceAreaCode = data.NotificationVoiceAreaCode;
$scope.NotificationMethods.NotificationVoicePhoneNumber = data.NotificationVoicePhoneNumber;
$scope.NotificationMethods.NotificationVoiceExtension = data.NotificationVoiceExtension;
}
Figured it out. I was declaring the controller on the view used in ng-include. Removing that and letting the view inherit controller from surrounding view solved issue.

Radio button in controller scope are not working in angular

I have form where i want to submit the whole data everything is fine except the radio button. The problem occurs when the radio buttons are in controller scope but they work fine out of controller scope. i am getting all other fields value properly except the radio button and i dont know where i am making mistake i am confuse why its not working...
Here is the angular script which is working fine...
//handling form controller
app.controller('myForm',function($http,$scope){
$scope.formData={};
$scope.saveCashbook=function()
{
console.log(this.formData);
$http({
method: "POST",
url: 'cashbook/save_cash_entry',
data: $.param($scope.formData),
headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
}).success(function (data) {
if (data.status == 'success') {
alert('all okay');
} else {
alert(data)
}
});
}
});
Here is my html in which two way data-binding isnt working while the radio buttons are in scope and when i placed them out from controller scope two way data binding start working but than i wont be able to get my radio button value in my controller where i am saving them to database.
<div class="col-sm-12" ng-controller="myForm">
<form name="supplier_form" id="myform" ng-submit="saveCashbook()" >
<div class="form-group col-sm-2" style="padding-top:30px;">
<label for="" class="label label-info">جمع</label>
<label class="control-label radio-inline">
<input type="radio" class="purple" value="jama" name="jamabanam" ng-model="formData.jamabanam" >
</label>
<label for="" class="label label-danger">بنام</label>
<label class="control-label radio-inline">
<input type="radio" class="purple" value="banam" name="jamabanam" ng-model="formData.jamabanam" >
</label>
</div>
<div class="form-group col-sm-2">
<label for="packing" class="control-label">رجسٹر</label>
<select id="register" name="register_id" ng-model="formData.register_id" class="form-control search-select two" >
<option value=""> </option>
<? $query=$this->dba->get_dropdown('register',array('id','name'));
foreach($query as $key=>$value):
?>
<option value="<?=$key?>"><?=$value; ?></option>
<? endforeach;?>
</select>
</div>
<div class="form-group col-sm-4">
<label for="raqam" class="control-label">نام</label>
<select id="name" name="name" ng-model="formData.name" class="form-control search-select two"></select>
</div>
<div class="form-group col-sm-2 has-error">
<label for="nuqsani-raqam" class="control-label">کھاتہ نمبر</label>
<input type="text" class="form-control" name="khata_id" ng-model="formData.khata_id" id="khata_no" >
</div>
<div class="form-group col-sm-2 has-success">
<label for="nuqsani-raqam" class="control-label">رقم</label>
<input type="text" name="raqam" class="form-control" ng-model="formData.raqam" id="raqqam">
</div>
<div class="form-group col-sm-12">
<label for="raqam" class="control-label">تفصیل</label>
<input type="text" name="details" ng-model="formData.details" id="details" class="form-control" >
</div>
<input type="submit" value="submit" name="submit" id="submit">
</form>
</div>
Here is my php function where i am priniting the whole $_POST
public function save_cash_entry()
{
print_r($_POST);
exit();
}

Categories