convert decimal value from database into autonumeric in input value when edit - laravel

Hello i've been trying to call my decimal value from my database and put it back into autonumeric with thousand separator value when user tried to edit it, here for example :
here are the input value when user try to create new order :
And here was the input value when user try to edit the order, and the data will be NULL in the database when user submit the value, even with the decimal inside the value :
It change the value into decimal value from the database, and when user tried to hover the input it completely remove the value like this :
here is the index.blade.php which is the value is taken from database :
$('body').on('click', '.editMediaOrder', function(){
var id = $(this).data('id');
$.get('media-order/'+id+'/edit', function (data){
$('#modalHeading').html("Edit Media Order");
$('#btn-update').val("Update");
$('#editMediaOrderSubmitButton').val("edit-media-order");
$('#editMediaOrderSubmitButton').prop('disabled',false);
$('#editMediaOrderModal').modal('show');
$('#editMediaOrderModal').modal('hide');
$('#id_edit').val(data.id);
$('#nomor').val(data.nomor);
$('#nomor_reference').val(data.nomor_reference);
$('#periode_start_edit').val(data.periode_start);
$('#periode_end_edit').val(data.periode_end);
$('#category_id').val(data.category_id);
$('#type_id').val(data.type_id);
$('#agency_code').val(data.agency_code);
$('#agency_name').val(data.agency_name);
$('#advertiser_name').val(data.advertiser_name);
$('#advertiser_code').val(data.advertiser_code);
$('#brand_code').val(data.brand_code);
$('#brand_name').val(data.brand_name);
$('#version_code').val(data.version_code);
$('#nett_budget').val(data.nett_budget);
$('#gross_value').val(data.gross_value);
$('#nett_cashback').val(data.nett_cashback);
$('#nett_bundling').val(data.nett_bundling);
$('#spot').val(data.spot);
$('#accountexecutive_name').val(data.accountexecutive_name);
$('#group_id').val(data.group_id);
$('#userto_name').val(data.userto_name);
$('#notes').val(data.notes);
$('#attachment_name').val(data.attachment_name);
})
});
i've been trying to using jquery and ajax to create the thousand separator at first but ended up using an autonumeric instead, is there was a way to convert the decimal value from database into autonumeric with thousand separator, so that user wont have to input another value and the database will also recognize it?, thank you for your time, and forgive me if there was an spelling error, thanks again!.

function defineMaskMoney() {
$('.your input class').maskMoney({thousands: '.', decimal: ',', affixesStay: true});
}
this is for query money format.
number_format($yourprice, 2, ',', '.');
this is for backend format to money.

Been trying to find out myself that in the end i'll ended up using jquery number, which is very helpfull, and i just change some of my input to this in my index.blade.php :
$('#nett_budget').on('input',function(){
var nettbudget = parseInt($('#nett_budget').val());
var nettcashback = parseInt($('#nett_cashback').val());
var nettbundling = parseInt($('#nett_bundling').val());
var grossvalue = parseInt($('#gross_value').val());
});
and :
$(function(){
$('#nett_budget').number(true);
$('#nett_bundling').number(true);
$('#gross_value').number(true);
$('#nett_cashback').number(true);
});
thanks again for helping me, and your time for reading my question.

Related

Remove blank column in jqGrid - Pivot

I have created a jqGrid - Pivot table JSFiddle example: here.
In this It should not print the line if Component Type value is blank, I Used this empty column, to show all periods(months) in the year, which is mandatory.
Need help in removing that blank line. and also is it possible to remove the last sum column 2015 from grid, if so how?
You includes dummy data with ComponentType:"" group which you don't want to display. So the best solution which I see would be to include the data in the input pivot data only, but don't use the dummy data in the grid data. jqPivot uses datatype: "jsonstring" to prevent additional sorting of previously sorted data. The input data will be placed as the value of datastr option. So one can use the following onInitGrid to remove the dummy data before the data will be processed by jqGrid:
onInitGrid: function () {
var p = $(this).jqGrid("getGridParam"),
userdata = p.datastr.userdata;
p.datastr = $.grep(p.datastr, function (item) {
return item.ComponentType !== "";
});
p.datastr.userdata = userdata;
}
see the modified demo http://jsfiddle.net/OlegKi/b47ocLd7/11/.

ALERT SESSION VALUE FROM first page to 2nd page using JQuery,ajax, or javascript

hi guyz this is my first time here. ahmmm i'd like to ask some question regarding session. ahmm
how i cant alert session value from first page to 2nd page using jquery,ajax, or javascript??
please help, im new on that language. ):
You can pass value from one page to other using url query string.
one link to second page add data as parameter like http://your-url.com?data=user-session-value
in the second page call the below javascript function in onload or where you need value
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
you can alert the value like alert(getParameterByName('data'));
In this way your data will show in url. if you don't want to show it then use localstorage. But you need to be in same domain. I mean u can't pass data from one website to other.
In page one just set the data in local storage like localStorage.setItem('data', 'user-session-value');To alert the data in second page call alert(localStorage.getItem('data'));
Hope this can solve your issue... Happy coding...

How to get value of dynamically added fields while doing Form Editing in JqGrid

I have one jqgrid which is having few columns. One of the column represent URLs. While showing the data in grid format, every url apears one after another seperated by ;(semicolon). When I double click a row, I get Form Window and in block onInitializeForm based on number of ;(semicolon)'s count, I am showing every URL in different inputbox. So the user can edit/update each one individualy.
But I am getting problem when there are more than one URL entry and after making changes when I submit the window, I get only first URL's data in my beans attribute. Others just get disappeared.
I saw the postdata in 'beforeSubmit' method and this is also showing only first input box's value.
Could you please help me, how to get value from those dynamically added extra fields?
If you need more info, please tell me. I am stuck on this for more than three days.
Update :-
What I did is,
in
beforeSubmit : function(postdata, formid) {
var val=";";
$("p textarea").each(function (index) {
val = val + $("#p_scnt" +(index+1)).val() + ";";
});
$('#url').val($("#url").val() + val);
return[true, ""];
}
"url" is my jqgrid column and "p_scnt" is the id of all newly created textboxes.
Its not setting valud back to URL column
I solved it using another way.
beforeSubmit : function(postdata, formid) {
var val=";";
$("p textarea").each(function (index) {
val = val + $("#p_scnt" +(index+1)).val() + ";";
});
postdata["url"] = postdata["url"] + val;
return[true, ""];
}

jqgrid inline saving with clientArray throws error

I am new to jqGrid and have created a simple grid with local data with editurl set to clientArray. I am using inline navigation. I can edit a row and when I press the save button, the rows gets update. So far so good.
When I press on add row button, a new empty is row is inserted. When I type in there some data and click on the save button, I get the error message:
Uncaught TypeError: Cannot read property 'extraparam' of undefined jquery.jqGrid.min.js:398
The documentation only tells how the saveRow method should be called. But, apparently the inline navigator is calling it automatically. Which is perfect. But I guess I still need to set some parameters correctly so that it does not throw the error and saves the newly added row.
Hope some jqGrid guru has a good tip. Thanks.
function createTable(data,colNames,colModel,caption ){
...
$(table).jqGrid({ data:data,
datatype: "local",
height: 'auto',
colNames:colNames,
pager:'#'+pagerid,
colModel:colModel,
viewrecords: true,
caption:caption,
editurl:'clientArray',
});
var nav = $(table).jqGrid('navGrid','#'+pagerid,{edit:false,add:false,del:false});
$(table).jqGrid('inlineNav','#'+pagerid);
$(table).jqGrid('gridResize',{minWidth:350,maxWidth:800,minHeight:80, maxHeight:350});
$('#gbox_'+tableid).draggable();
}
You are right, It's a bug in inlineNav method. The lines
if(!o.addParams.addRowParams.extraparam) {
o.addParams.addRowParams.extraparam = {};
}
uses o.addParams.addRowParams.extraparam, but default value of parameter of addParams (see here) defined as addParams : {} and not as addParams : {addRowParams: {}}. So the expression o.addParams.addRowParams is equal undefined and o.addParams.addRowParams.extraparam is the same as undefined.extraparam which produce null reference exception.
I posted the corresponding bug report to trirand and the problem will be fixed in the next version of jqGrid.
As a workaround you can replace the line
$(table).jqGrid('inlineNav','#'+pagerid);
with the line
$(table).jqGrid('inlineNav','#'+pagerid, {addParams: {addRowParams: {}}});
Some common additional remarks to your code:
I strictly recommend that you always use gridview: true option which will improve performance of your code without any disadvantages
I recommend you to use autoencode: true option per default. Per default jqGrid interpret input data of the grid as HTML fragments which must be well formatted. So if you would try to display the data like a < b you can have problems because < is special character in HTML. If you would use autoencode: true option the input data will be interpreted as text instead of HTML fragments.
I recommend you remove index property from your model if you assign always the same value for index and name properties.
I recommend you to provide id property with unique values for every item of the input data. You should understand that jqGrid always assign id attribute for every row of grid. The value must be unique over all HTML elements on the page. If you get the data from the server and the data have native unique id from the database it's recommended to use the value as the value of id property. If you don't specify any id property jqGrid assign values 1, 2, 3, ... as the id values of rows (rowids). If you use more as one jqGrids on the page and don't provide unique id values you will have id duplicates which is HTML error.
I recommend you to use idPrefix option of jqGrid. If you have two grids on the page and you don't fill (and don't need) any id for data items then you have have id duplicates (id="1", id="2" etc in both grids). If you would define idPrefix: "g1_" for one grid and idPrefix: "g2_" option for another grid then the rowids of the first grid will be id="g1_1", id="g1_2" etc in the first grid and id="g2_1", id="g2_2" in the second grid. Even if you fill the id from the server then you provide unique id inside one table, but the ids from two tables of database can have the same id. So the usage of different idPrefix option for every grid will solve the problem of id duplicates in very simple way.
I'm having this same issue but my jqgrid markup is completely different (maybe newer version?)
I can use inline to edit and save a row, but adding a row will not save. I am not sure what the issue is.
<?php
ini_set("display_errors","1");
require_once 'jq-config.php';
// include the jqGrid Class
require_once ABSPATH."php/jqAutocomplete.php";
require_once ABSPATH."php/jqCalendar.php";
require_once ABSPATH."php/jqGrid.php";
// include the driver class
require_once ABSPATH."php/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
$grid->SelectCommand = 'SELECT Serial, Type, Customer, Date, Notes FROM rmas';
$resize = <<<RESIZE
jQuery(window).resize(function(){
gridId = "grid";
gridParentWidth = $('#gbox_' + gridId).parent().width();
$('#' + gridId).jqGrid('setGridWidth',gridParentWidth);
})
RESIZE;
$grid->setJSCode( $resize);
// set the ouput format to json
$grid->dataType = 'json';
$grid->table ="rmas";
$grid->setPrimaryKeyId("Serial");
// Let the grid create the model
$grid->setColModel();
// Set the url from where we obtain the data
$grid->setUrl('rmaform.php');
$grid->cacheCount = true;
//$grid->toolbarfilter = true;
$grid->setGridOptions(array(
"caption"=>"RMAs",
"rowNum"=>50,
"sortname"=>"Serial",
"hoverrows"=>true,
"rowList"=>array(50,100,200),
"height"=>600,
"autowidth"=>true,
"shrinkToFit"=>false
));
$grid->callGridMethod('#grid', 'bindKeys');
// Change some property of the field(s)
$grid->setColProperty("Serial", array("align"=>"center","width"=>40));
$grid->setColProperty("Type", array("align"=>"center","width"=>40));
$grid->setColProperty("Customer", array("align"=>"center","width"=>65));
$grid->setColProperty("Date", array("align"=>"center","width"=>40));
$grid->setColProperty("Notes", array("align"=>"left","width"=>500));
// navigator first should be enabled
$grid->navigator = true;
$grid->setNavOptions('navigator', array("add"=>false,"edit"=>false,"excel"=>true));
// and just enable the inline
$grid->inlineNav = true;
$buttonoptions = array("#pager", array(
"caption"=>"Enable Cells",
"onClickButton"=>"js:function(){ jQuery('#grid').jqGrid('setGridParam',{cellEdit: true});}", "title"=> "Enable Excel like editing"
)
);
$grid->callGridMethod("#grid", "navButtonAdd", $buttonoptions);
$buttonoptions = array("#pager", array(
"caption"=>"Disable Cells",
"onClickButton"=>"js:function(){ jQuery('#grid').jqGrid('setGridParam',{cellEdit: false});}" , "title"=> "Disable Excel like editing"
)
);
$grid->callGridMethod("#grid", "navButtonAdd", $buttonoptions);
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
$conn = null;
?>

"The field width must be a number." at client side

I am using jquery for client side validation together with data annotations. Everything is working fine but I would like to localize a message when a non numeric value is entered in numeric textbox. But for client side validation asp.net mvc is using it's own resource file with key 'ClientDataTypeModelValidatorProvider_FieldMustBeNumeric'.
How can I do?
Thanks.
Look for solution at the end of this page:
http://jwwishart.wordpress.com/2010/03/22/custom-server-and-client-side-required-validator-in-mvc-2-using-jquery-validate/
I checked this in my MVC 3 RTM project and it works well.
I had the same problem because I'm Italian and here decimal numbers are formatted with comma instead of dot. So, what in the US is 1,000.12 here is written 1.000,12.
That's how I solved, after some searching:
MVC3 already includes the script jquery.validate.js/jquery.validate.min.js
and that's amazing.
Then I added another script -- methods-it.js -- taken from jquery validate plugin localization folder and changed a little.
jQuery.extend(jQuery.validator.methods, {
date: function (value, element) {
return this.optional(element) || /^\d\d?\.\d\d?\.\d\d\d?\d?$/.test(value);
},
number: function (value, element) {
return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value);
},
range: function (value, element, param) {
var val = value.replace(",", "#").replace(".", ",").replace("#", ".");
return this.optional(element) || (val >= param[0] && val <= param[1]);
}
});
This small code deals with dates (Italian formatting), floating numbers and range of values.
It works great, now!
Unfortunately this is just a direction and not THE solution, because it has to be corrected for every locale.
I found it easier to just use DataAnnotations on the view model:
[RegularExpression("([0-9]+)", ErrorMessageResourceType = typeof(ErrorMessage), ErrorMessageResourceName = "NumberInvalid")]

Resources