I hope someone will be able to help me.
This code works fine :
cy.request({
method: 'POST',
url: surl,
log : true,
auth: {
user: 'xxxx',
pass: 'xxxx'
},
headers: {
//'Content-Type': 'application/json; charset=utf-8',
},
body:{
Obpos_Applications_ID: 'AE765712BBCC47669475A5478EEFA8B3',
inpKeyName: 'inpobposApplicationsId',
inpTabId: 'FF80818132F311740132F3233778004B',
inpTableId: 'FF80818132F311740132F31E2C9A0016',
inpadClientId: '48429219C6DA47AEB1F7958F1375D601',
inpadOrgId: '736B1011B45D4B96B31E329A15DB437A',
inpcBpartnerId: '6A7F4BF891884403A48E1DC0921FA71B',
inpcurrentCacheSessionId: '7139E00CEB614C6C947511AFCC6C20C5',
inpdefaultwebpostab: 'scan',
inpdocumentnoPadding: '7',
inpemAc3Host: null,
inpemAc3Interface: '',
inpemAc3Port: null,
inpemAc3Printsinfo: 'Y',
inpemAc3Terminal: null,
inpemGcnvGcseqLastnum: '0',
inpemGcnvGcseqPrefix: 'CAISSE_37_99',
inpemObcfrIsblockchained: 'N',
inpemObposcsCopyTerminal: 'N',
inpemPossBusinessdate: '27-11-2020',
inpemPossClosesession: 'N',
inpemPossOpensession: 'N',
inpemPossSession: 'N',
inpemPossStoreopen: null,
inpfullinvdocnoPrefix: 'CAISSE_37_99',
inpfullinvlastassignednum: '0',
inpfullretinvdocnoPrefix: 'CAISSE_37_99',
inpfullretinvlastassignednum: '0',
inphardwareurl: 'http://localhost:8090/printer',
inpisactive: 'Y',
inpislinked: 'Y',
inpismaster: 'N',
inpkeyColumnId: 'Obpos_Applications_ID',
inplastassignednum: '369',
inpmasterterminalId: null,
inpname: 'CAISSE_37_99_Automate',
inpobposApplicationsId: 'AE765712BBCC47669475A5478EEFA8B3',
inpobposCBpartnerLocId: '9AE0222DE3AD46498CFBB360DD1ADAD4',
inpobposTerminaltypeId: 'B5AC8D0ED0654B89AAC1A299AD40B269',
inpopenhardwareurl: 'N',
inporderdocnoPrefix: 'CAISSE_37_99',
inpprintertype: 'HWM',
inpprintoffline: 'N',
inpquotationdocnoPrefix: 'CAISSE_37_99',
inpquotationslastassignednum: '0',
inpreturndocnoPrefix: '37_99R',
inpreturnslastassignednum: '1',
inpscaleurl: null,
inpsimpinvdocnoPrefix: 'CAISSE_37_99SINV',
inpsimpinvlastassignednum: '0',
inpsimpretinvdocnoPrefix: 'CAISSE_37_99',
inpsimpretinvlastassignednum: '0',
inpterminalKeyId: 'CAISSE_37_99',
inpterminalLastbenchmark: null,
inpterminalLastcachegeneration: '26-11-2020 15:46:11',
inpterminalLastcashupcompleted: '17-03-2021 13:55:05',
inpterminalLastfullrefresh: null,
inpterminalLasthwmjavainfo: 'Java(TM) SE Runtime Environment (build 1.8.0_271-b09)',
inpterminalLasthwmrevision: '58d64521ad1b',
inpterminalLasthwmversion: '1.0.5600',
inpterminalLastincrefresh: null,
inpterminalLastjsgeneration: null,
inpterminalLastlogindate: null,
inpterminalLastloginuser: 'B728314713644F8EBD2F6E80507D8E94',
inpterminalLastordersynchronized: null,
inpterminalLastticketloaded: null,
inpterminalLasttimeinoffline: '16-10-2020 09:21:45',
inpterminalLasttimeinonline: null,
inpunlinkdevice: 'N',
inpvalue: '990037',
inpwindowId: 'FF80818132F311740132F322B8CD0048',
keyColumnName: 'Obpos_Applications_ID',
keyProperty: 'id',
keyPropertyType: '_id_13',
_buttonValue: 'DONE',
_params: {}
}
})
.then((responseactions) => {
expect(responseactions.status).to.eq(200)
cy.log(responseactions.body)
});
but if i use a parameter, it is ko.
cy.request({
method: 'POST',
url: surl,
log : true,
auth: {
user: 'xxxx',
pass: 'xxxx'
},
headers: {
//'Content-Type': 'application/json; charset=utf-8',
},
body:{
sbody
}
})
.then((responseactions) => {
expect(responseactions.status).to.eq(200)
cy.log(responseactions.body)
});
I would guess that sbody is
const sbody = {
Obpos_Applications_ID: 'AE765712BBCC47669475A5478EEFA8B3',
inpKeyName: 'inpobposApplicationsId',
...
}
If so you want
cy.request({
method: 'POST',
url: surl,
log : true,
auth: {
user: 'xxxx',
pass: 'xxxx'
},
headers: {
//'Content-Type': 'application/json; charset=utf-8',
},
body: sbody
})
.then((responseactions) => {
expect(responseactions.status).to.eq(200)
cy.log(responseactions.body)
});
Related
I am have an api like this:
(This is a wechat-miniprogram api.)
wx.request({
url: 'test.php',
data: {
x: '',
y: ''
},
header: {
'content-type': 'application/json'
},
success (res) {
console.log(res.data)
},
fail(err) {
console.log(err)
},
complete(res) {
console.log(res.data)
}
})
However I want to use it like this:
(I want to use it like an observable.)
rxwx.request({
url: 'test.php',
data: {
x: '',
y: ''
},
header: {
'content-type': 'application/json'
},
}).subscribe(
(res) => {
console.log(res.data)
},
(err) => {
console.log(err)
},
(res) => {
console.log(res.data)
}
)
I cannot transform wx.login with bindCallback or bindNodeCallback. Please help. Thanks in advance :D
Use Observable constructor instead
const request=new Observable(emitter=>{
wx.request({
url: 'test.php',
data: {
x: '',
y: ''
},
header: {
'content-type': 'application/json'
},
success:emitter.next
fail:emitter.error
complete:emitter.complete
})
return ()=>{ //... clearn up logic here }
}
I am trying to perform validation on one of the fields in the form.
Only if the value for that field exists will I be able to invoke the API, if not an error message will be thrown.
I tried various examples from SweetAlert2's website. I just want the validation for one of the fields.
Swal.fire({
title: 'Are you sure you want to Save the Notes?',
type: 'info',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes'
}).then((result) => {
console.log('result.value',result.value);
if (result.value) {
Swal.fire( {
title: 'Download Notes',
html:"<div class='b'><p>ID</p></div><input id='swal-input2' class='swal2-input' required/><div class='b'><p>Notes</p></div><input id='swal-input1' class='swal2-input' autofocus minlength='500' >",
confirmButtonText: 'Save',
preConfirm: (login) => {
console.log('document.getElementById(swal-input2).value',document.getElementById('swal-input2').value);
request_string = {
"Request":
[
{
"Col1": "value1",
"Col1": "value2",
"Col1": document.getElementById('swal-input2').value,
"Col1": document.getElementById('swal-input1').value,
}
]
};
fetch('API_URL', {
headers: {
'Accept': 'application/json, text/plain, application/xml, */*',
'Content-Type': 'application/json',
'Access-Control-Allow-Headers': 'Content-Type',
},
method: 'POST',
body: JSON.stringify(request_string)
}
).then(response => {
if (response.status !== 200) {
return;
}
response.text().then(data => {
response_data = data;
response_jsonObj = JSON.parse(response_data);
});
}).catch(error => this.setState({ error }));
},
allowOutsideClick: () => !Swal.isLoading()
}).then((result) => {
swal({
title: " Your request is being processed!",
icon: "success",
confirmButtonText: 'OK'
}).then((okay) => {
if (okay) {
history.push('/page1');
history.push('/page2');
}
});
});
}
})
If you just want to make sure that the first input (i.e. swal-input2) is not null, then you simply need to add preConfirm like that:
preConfirm: () => {
if (document.getElementById('swal-input2').value) {
// Handle return value
} else {
Swal.showValidationMessage('First input missing')
}
}
You can find the working solution here
For those who try to get every inputs with a required attribute try this :
inputAttributes: {
input: 'number',
required: 'true'
}
Hi folks this as been fixed here is the code sample for the same :
Swal.fire({
title: 'Are you sure you want to Save the Notes?',
type: 'info',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes'
}).then((result) => {
console.log('result.value',result.value);
if (result.value) {
Swal.fire( {
title: 'Download Notes',
html:"<div class='b'><p>ID</p></div><input id='swal-input2' class='swal2-input' required/><div class='b'><p>Notes</p></div><input id='swal-input1' class='swal2-input' autofocus minlength='500' >",
confirmButtonText: 'Save',
preConfirm: () => {
if((document.getElementById('swal-input2').value == "") || (document.getElementById('swal-input2').value == '') || ((document.getElementById('swal-input2').value == null)) ){
Swal.showValidationMessage(
`ID is a required field`
)
}
}
}).then((result) => {
request-string = {
"Request":
[
{
"COL1": VALUE1,
"COL2": VALUE2,
"COL3": VALUE3,
"COL4": VALUE4,
"COL5" : VALUE5,
"COL6" : VALUE6,
"COL7": VALUE7
}
]
};
;
fetch('API_URL', {
headers: {
'Accept': 'application/json, text/plain, application/xml, */*',
'Content-Type': 'application/json',
'Access-Control-Allow-Headers': 'Content-Type',
},
method: 'POST',
body: JSON.stringify(request-string)
}
).then(response => {
if (response.status !== 200) {
return;
}
response.text().then(data => {
response_data = data;
response_jsonObj = JSON.parse(response_data);
this.setState({ state: response_jsonObj });
});
}).catch(error => this.setState({ error }));
swal({
title: "Request Submitted Successfully!",
icon: "success",
confirmButtonText: 'OK'
}).then((okay) => {
if (okay) {
history.push('/page1');
history.push('/page2');
}
});
});
Hallo I have the MemberController with this action:
public function anyData()
{
$members = DB::table('members')
->select(['id','email','firstname','lastname','address','zip','city','phone','mobile','work','birthdate']);
return Datatables::of($members)
->addColumn('action', function ($id) {
return 'Edit
<button class="btn" data-remote="/member/' . $id->id . '">Delete</button>
'; })->make(true);
}
This is the JS Code to get the table with the datas:
<script type="text/javascript">
var table = $('#datatable-member').DataTable({
responsive: true,
"language": {
"url": "{{ asset('/plugins/datatables/lang').'/'.Config::get('app.locale').'.json'}}"
},
processing: true,
serverSide: true,
ajax: '{{ route('member') }}',
columns: [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
{ data: 'id', name: 'id' },
{ data: 'email', name: 'email' },
{ data: 'firstname', name: 'firstname' },
{ data: 'lastname', name: 'lastname' },
{ data: 'address', name: 'address' },
{ data: 'zip', name: 'zip' },
{ data: 'city', name: 'city' },
{ data: 'phone', name: 'phone' },
{ data: 'mobile', name: 'mobile' },
{ data: 'work', name: 'work' },
{ data: 'birthdate', name: 'birthdate' },
{data: 'action', name: 'action', orderable: false, searchable: false}
],
order: [[1, 'asc']]
}).$('.btn[data-remote]').on('click', function (e) {alert('test') })
;
</script>
The tables shows the data correctly, the edit link and delete button appears correctly but the action (at the moment only an alert) in the delete button is not working, when i click nothing happens.
I tryied also this on the javascript but nothing changed:
$('#datatable-member').DataTable().on('click', '.btn-delete[data-remote]', function (e) {alert('test') })
From Laravel framework for delete you need to have form validation by using X-CSRF Token. Try this to send a proper request for delete if you are using Laravel resource you can use below code, but make sure your datatable edit column are using the btn-delete class, as you are right now using the btn class.
<script type="text/javascript">
var table = $('#datatable-member').DataTable({
responsive: true,
"language": {
"url": "{{ asset('/plugins/datatables/lang').'/'.Config::get('app.locale').'.json'}}"
},
processing: true,
serverSide: true,
ajax: '{{ route('member') }}',
columns: [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
{ data: 'id', name: 'id' },
{ data: 'email', name: 'email' },
{ data: 'firstname', name: 'firstname' },
{ data: 'lastname', name: 'lastname' },
{ data: 'address', name: 'address' },
{ data: 'zip', name: 'zip' },
{ data: 'city', name: 'city' },
{ data: 'phone', name: 'phone' },
{ data: 'mobile', name: 'mobile' },
{ data: 'work', name: 'work' },
{ data: 'birthdate', name: 'birthdate' },
{data: 'action', name: 'action', orderable: false, searchable: false}
],
order: [[1, 'asc']]
});
$('#datatable-member').on('click', '.btn-delete[data-remote]', function (e) {
e.preventDefault();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var url = $(this).data('remote');
// confirm then
$.ajax({
url: url,
type: 'DELETE',
dataType: 'json',
data: {method: '_DELETE', submit: true}
}).always(function (data) {
$('#datatable-member').DataTable().draw(false);
});
});
Below code not going to succeed, it is showing failure message.. anybody can help
$.ajax({
type: 'GET',
url: 'xyz.com/form_api.php',
data: {
name: 'John',
email: '123333',
mobile: 'deep#gmail.com',
message: 'Test'
},
success: function(response) {
console.log(response);
$('#contact_form #contact_results2').html('Success');
},
error: function(errorThrown) {
console.log(errorThrown);
$('#contact_form #contact_results2').html('failed');
}
});
Try this code:
$.ajax({
type: 'GET',
url: 'xyz.com/form_api.php',
data: { 'name': 'John', 'email': 'deep#gmail.com', 'mobile': '123333', 'message': 'Test'
},
success: function(response)
{
console.log( response );
$("#contact_form #contact_results2").html("Success");
},
error: function(errorThrown)
{
console.log( errorThrown );
$("#contact_form #contact_results2").html("failed");
},
});
I'm using kendoGrid and my remote data is from php.
this is an example of the grid:
$('#grid').kendoGrid({
columns: [
{field: 'Agent_Code', title: 'Agent code'},
{field: 'Agent_Name', title: 'Agent name'},
{field: 'Short_Name', title: 'Short name'},
{field: 'More_Info', title: 'More info'},
{command: {name: 'edit'}}
],
toolbar: [
{name: 'create'}
],
dataSource: {
transport: {
create: {
url: 'ajax/create.php',
type: 'POST',
dataType: 'json'
},
read: {
url: 'ajax/read.php',
type: 'POST',
dataType: 'json'
},
update: {
url: 'ajax/update.php',
type: 'POST',
dataType: 'json'
},
destroy: {
},
},
schema: {
type: 'json',
data: 'data.results',
model: {
id: 'Agent_Code',
fields: {
Agent_Code: {editable: true, nullable: false, type: 'string'},
Agent_Name: {editable: true, nullable: false, type: 'string'},
Short_Name: {editable: true, nullable: false, type: 'string'},
More_Info: {editable: true, nullable: false, type: 'string'}
}
}
}
}
});
The grid populates correctly because I set "dataSource.schema.data" to "data.results" so the grid know how to locate the data at the server response.
server 'json' response structure for "transport.read" is:
{
code: 'ok',
data: {
id: [' ', ' '],
results: [
{Agent_Code: ' ', Agent_Name: ' ', Short_Name: ' ', More_Info: ' '},
{Agent_Code: ' ', Agent_Name: ' ', Short_Name: ' ', More_Info: ' '}
]
}
}
My problem is that I don't understand how to do that for "dataSource.transport.create" and "dataSource.transport.update" the server receive the data correctly, store it to DB and response with:
{
code: 'ok',
text: 'operation succeeded'
}
but the grid don't understand that everything is OK and update the grid.
What is missing here?
Regards
You need to modify your schema definition adding errors to it.
schema : {
type : 'json',
data : 'data.results',
model: {
id : 'Agent_Code',
fields: {
Agent_Code: {editable: true, nullable: false, type: 'string'},
Agent_Name: {editable: true, nullable: false, type: 'string'},
Short_Name: {editable: true, nullable: false, type: 'string'},
More_Info : {editable: true, nullable: false, type: 'string'}
}
},
errors : function(a) {
return a.code !== "ok";
}
}
This errors function returns true or false depending on code.
In addition and since you seems to do not return the record when it is updated or inserted, you should modify data to do not try to find it when update or create but find it when read.
You might define it as:
data : function (a) {
if (a.data && a.data.results){
return a.data.results;
} else {
return null;
}
},
Now, the schema definition would be:
schema : {
type : 'json',
data : function (a) {
if (a.data && a.data.results){
return a.data.results;
} else {
return null;
}
},
model: {
id : 'Agent_Code',
fields: {
Agent_Code: {editable: true, nullable: false, type: 'string'},
Agent_Name: {editable: true, nullable: false, type: 'string'},
Short_Name: {editable: true, nullable: false, type: 'string'},
More_Info : {editable: true, nullable: false, type: 'string'}
}
},
errors : function(a) {
return a.code !== "ok";
}
}
NOTE: If you always return ok then you might avoid defining errors, the only important part is redefining data.
EDIT: You can read more in KendoUI site:
About using it here and specifically on using errors and error here.
You can also check DataSource.schema.errors documentation and DataSource.error](http://docs.kendoui.com/api/framework/datasource#events-error) event handler documentation.