genxcoders wrote: Thanks for the start. I will get on with it and get back!
You are welcome. Hopefully you can get sorted the final bits on your own.
genxcoders wrote: Thanks for the start. I will get on with it and get back!
(a) I suggest to make your 'bill' form as a whole - a databound form, bound to 'bills.php' template with mode='create'. So upon a successful submission the form will create a new cloned page in backend with relation of a bill to the products as one-to-many (you have to have that relation established).
<cms:editable name='bill_product' label='Bill Product' type='relation' masterpage='product.php' required='1' order='4' />
(b) Initially place one pre-filled dropdown in the form as a regular input (use cms:pages to create the list of options), mind the name must have [] brackets and final look could be like this with value having the id of the page:.....
<cms:set submit_success="<cms:get_flash 'submit_success' />" />
<cms:if submit_success >
<div class="row">
<div class="col-md-12 text-center">
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong>Success!</strong> Bill created successfully!
<h2>Selected product id(s) are: <cms:show frm_bill_product /></h2>
</div>
</div>
</div>
</cms:if>
<div class="col-md-12">
<div class="gxcpl-data-container gxcpl-box-border gxcpl-bg-white gxcpl-padding">
<div class="gxcpl-ptop-10"></div>
<cms:form masterpage=k_template_name mode='create' enctype='multipart/form-data' method='post' anchor='0' >
<cms:if k_success >
<cms:db_persist_form
_invalidate_cache='1'
_auto_title='1'
bill_product="<cms:show frm_bill_product />"
/>
<cms:if k_success>
<cms:set_flash name='submit_success' value='1' />
<cms:redirect url="<cms:route_link 'create_bills' />" />
</cms:if>
</cms:if>
<cms:if k_error >
<div class="row">
<cms:each k_error >
<div class="col-md-6">
<div class="alert alert-danger">
<cms:show item />
</div>
<div class="gxcpl-ptop-10"></div>
</div>
</cms:each>
</div>
</cms:if>
<!-- Billing Date -->
<div class="row">
<div class="col-md-2">
<label for="bdate">Billing Date</label>
<div class="gxcpl-ptop-10"></div>
</div>
<div class="col-md-10">
<div style="height: 34px; line-height: 34px;">
<cms:date format='F d, Y' />
</div>
<cms:hide><cms:input name="bdate" type="bound" value="<cms:date />" /></cms:hide>
<div class="gxcpl-ptop-10"></div>
</div>
</div>
<!-- Billing Date -->
<!-- Bill Number -->
<div class="row">
<div class="col-md-2">
<label for="billno">Bill No</label>
<div class="gxcpl-ptop-10"></div>
</div>
<div class="col-md-10">
<cms:input class="form-control" name="billno" type='bound' />
<div class="gxcpl-ptop-10"></div>
</div>
</div>
<!-- Bill Number -->
<!-- Showroom -->
<div class="row">
<div class="col-md-2">
<label for="srname">Select Dealer</label>
<div class="gxcpl-ptop-10"></div>
</div>
<div class="col-md-10">
<cms:hide><cms:input type='bound' name='dname_rel' class="form-control" /></cms:hide>
<select name="f_dname_rel" class="form-control">
<option selected disabled >Select Dealer</option>
<cms:pages masterpage=k_user_template order='asc' id=extended_user_id >
<cms:if extended_user_id gt '2'>
<option value="<cms:show k_page_title />">
<cms:show k_page_title />
</option>
</cms:if>
</cms:pages>
</select>
<div class="gxcpl-ptop-10"></div>
</div>
</div>
<!-- Showroom -->
<!-- Add Product -->
<div class="row">
<div class="col-md-12 text-center">
<h4>Add Product(s)</h4>
<div class="gxcpl-ptop-10"></div>
</div>
</div>
<!-- Add Product -->
<!-- Product List -->
<div class="row">
<div class="col-md-12">
<table id="myTable" class="table order-list" width="100%" style="border: 1px solid rgba(0,0,0,0.35);">
<thead style="height: 34px; line-height: 34px;">
<tr>
<th class="text-center" width="60%">
Product Name
</th>
<th class="text-center" width="30%">
Warranty Validity
</th>
<th class="text-center" width="10%">
Delete
</th>
</tr>
</thead>
<tbody style="border: 1px solid rgba(0,0,0,0.35); height: 34px; line-height: 34px;">
<tr class="text-center">
<td>
<cms:hide>
<cms:input type='checkbox' name='bill_product' />
</cms:hide>
<select name="bill_product[]">
<option disabled selected value="">Select Product</option>
<cms:pages masterpage='product.php'>
<option value="<cms:show k_page_id />"><cms:show k_page_title /></option>
</cms:pages>
</select>
</td>
<td>
December 05, 2018
</td>
<td>
<button type="button" class="btn btn-danger btn-xs disabled">
<i class="fa fa-times"></i>
</button>
</td>
</tr>
</tbody>
</table>
</div>
<div class="col-md-12">
<button id="addrow" type="button" class="btn btn-default btn-xs">
<i class="fa fa-plus"></i> Add Product
</button>
<div class="gxcpl-ptop-20"></div>
</div>
</div>
<!-- Product List -->
<!-- Submit -->
<div class="row">
<div class="col-md-12">
<center>
<button type="submit" class="btn btn-success gxcpl-btn-text">
<i class="fa fa-save"></i> Create Bill
</button>
</center>
<div class="gxcpl-ptop-20"></div>
</div>
</div>
<!-- Submit -->
</cms:form>
</div>
<div class="gxcpl-ptop-20"></div>
</div>
// Add row in Billing
$(document).ready(function () {
var counter = 0;
$("#addrow").on("click", function () {
var newRow = $("<tr class='text-center'>");
var cols = "";
cols += '<td><select name="bill_product[]"><option disabled selected value="">Select Product</option><cms:pages masterpage="product.php"><option value="<cms:show k_page_id />"><cms:show k_page_title /></option></cms:pages></select></td>';
cols += '<td class="text-center">Warranty Date</td>';
cols += '<td><button type="button" class="ibtnDel btn btn-danger btn-xs"><i class="fa fa-times"></i></button></td>';
newRow.append(cols);
$("table.order-list").append(newRow);
counter++;
});
$("table.order-list").on("click", ".ibtnDel", function (event) {
$(this).closest("tr").remove();
counter -= 1
});
});
// Add row in Billing
<cms:editable name='dname_rel' label='Dealer Name' type='relation' masterpage=k_user_template has='one' order='3' required='1' />
<cms:input type='bound' name='dname_rel' class="form-control" />
<cms:hide><cms:input type='bound' name='dname_rel' class="form-control" /></cms:hide>
<select name="f_dname_rel" class="form-control">
<option selected disabled >Select Dealer</option>
<cms:pages masterpage=k_user_template order='asc' id=extended_user_id >
<cms:if extended_user_id gt '2'>
<option value="<cms:show k_page_title />">
<cms:show k_page_title />
</option>
</cms:if>
</cms:pages>
</select>
Thanks for the all the help so far. I have used your code and been able to get the things to work.
I am now stuck at the "dname_rel". It does not work.
Apart from this one field dname_rel rest all things are working.
Your thought(s) / suggestions(s) please.
Regards,
GenXCoders (Priya)