onsubmit error
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Hello, ksertkaya!
This particular error is caused by
Instead, the correct method is
But there is a problem in your code. fd.onsubmit(function() is initiated when you click Save button and then you click it again in your code. I am not sure what exactly you want to get as a result, but this will make you stuck in a loop, constantly calling alert() function.
This particular error is caused by
Code: Select all
fd.click.save();
Code: Select all
fd.save().click();
Cheers
Ah sorry, my bad..
Actually I want to add this code in my save button but it does not work in onClick event..
My code:
If title is 'Machine1', alert must shown 'ok' and save this item. Else alert('fail') and return the page...
function onRequestSucceeded() {
var uniqueMachine = fd.field('UniqueMachine').value();
var url = window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl + 'group/enys';
var ctx =new SP.ClientContext(url);
var oList = ctx.get_web().get_lists().getByTitle('Veri Girişi');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'UniqueMachine\' /><Value Type=\'Text\'>'+uniqueMachine+
'</Value></Eq></Where></Query></View>');
this.collListItem = oList.getItems(camlQuery);
ctx.load(collListItem);
ctx.executeQueryAsync(function()
{
var listItemInfo = '';
//alert('itemCount: '+collListItem.get_count());
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext())
{
var oListItem = listItemEnumerator.get_current();
var title = oListItem.get_item('Title');
if(title == 'Machine1')
{
alert('ok');
return true;
}
else return false; // Error
}
});
}
Actually I want to add this code in my save button but it does not work in onClick event..
My code:
If title is 'Machine1', alert must shown 'ok' and save this item. Else alert('fail') and return the page...
function onRequestSucceeded() {
var uniqueMachine = fd.field('UniqueMachine').value();
var url = window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl + 'group/enys';
var ctx =new SP.ClientContext(url);
var oList = ctx.get_web().get_lists().getByTitle('Veri Girişi');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'UniqueMachine\' /><Value Type=\'Text\'>'+uniqueMachine+
'</Value></Eq></Where></Query></View>');
this.collListItem = oList.getItems(camlQuery);
ctx.load(collListItem);
ctx.executeQueryAsync(function()
{
var listItemInfo = '';
//alert('itemCount: '+collListItem.get_count());
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext())
{
var oListItem = listItemEnumerator.get_current();
var title = oListItem.get_item('Title');
if(title == 'Machine1')
{
alert('ok');
return true;
}
else return false; // Error
}
});
}
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
fd.onsubmit wouldn't work with this code, since you are using async functions. There is a lot of code here and I can't guarantee that it would work properly as is. The best way to solve the issue would be to email your code and what you want to achieve in detail to our support team:
support@spform.com
support@spform.com
Cheers
-
- Posts: 18
- Joined: Wed May 17, 2017
I had to work around this as well as I wanted to perform an async REST query when the user pressed save before the form was submitted.
One way around this is to hide (don't delete or fd.save().click() wont work) the save button and create your own. You can then get the button to run an async call in a function for example and at the end of the call do fd.save().click()
e.g.
If you use the fd.onsubmit routine then you will find it will save it before it has a chance to complete the async code due to its nature. Tho I suppose you could call getData from within it and return true for .done and false for .fail.
One way around this is to hide (don't delete or fd.save().click() wont work) the save button and create your own. You can then get the button to run an async call in a function for example and at the end of the call do fd.save().click()
e.g.
Code: Select all
function onSave() {
getData() //function that runs async query
.done(function(data) {
...code to do here...
fd.save().click();
})
.fail(function(e) { ... });
}
-
- Information
-
Who is online
Users browsing this forum: No registered users and 5 guests