Page 1 of 1

Field is empty after saving

Posted: 08 Jul 2020
by TWendt
Hi all,

I'm a bit confused. The script add the current user name to a text field. When i save, the field is empty.

SP.SOD.executeOrDelayUntilScriptLoaded((function () {
if (fd.field('User').value() == '') {
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
ctx.load(web);
var user = web.get_currentUser();
user.retrieve();
ctx.executeQueryAsync(
function () {
fd.field('User').value(user.get_title());
});
}
}), "SP.js");
//disable field
fd.field('User').readonly(true);

What is wrong?

Best wishes
Tom

Re: Field is empty after saving

Posted: 09 Jul 2020
by mnikitina
Hello Tom,

Most browsers don’t send values of disabled fields to the server during the submission, so they will be lost. So you need to enable the field before the submission in onsubmit handler.

Code: Select all

fd.onsubmit(function () {
  fd.field('User').readonly(false);
  return true;
});

Re: Field is empty after saving

Posted: 16 Jul 2020
by TWendt
Hi Mnikitina

many thanks for your support. It works fine.

Bets wishes
Tom