Custom Form does not save values if field validation occurred
-
Thursday, March 06, 2008 11:05 PM
I have a custom New form that I am having problems with. If a user inputs all fields, and the form validation doesn't catch any problems, then the list item is saved with no problems.
If one of the form fields finds a problem such as a required field that wasn't entered or an invalid name in the people picker, then after the user corrects the problem and presses save the list item will get saved without the correct values from the form fields. The form fields still display the correct information before pressing save, but the list item that was saved does not have the same values as the form fields.
It seems that SharePoint:FormField are fine, but things such as SharePoint
VDropDownList will display the data after a form error, but will no longer keep the form data and therefore it doesn't get saved.Has anyone else had this problem? If so then have you found a fix?
All Replies
-
Wednesday, April 02, 2008 2:25 PM
I have also found that this only happens when validation triggers from the OK button being pressed. If a user presses the check box validation on the people picker, the people picker finds a problem, user corrects the problem and presses OK, then all fields are written to the SharePoint list with no problem. The problem only happens if validation finds a problem when the OK button is pressed.
Any ideas?
-
Tuesday, April 22, 2008 3:42 PM
I have had a similar issue. My problem stems from the fact that I am trying to pass data into the form through a parameter. To do this I used an ASP field to contain the data in a SharePoint custom form (created using SharePoint Designer). If someone messes up on a date field and the SP Validation kicks in, the ASP fields still contain info, but are not saved. To see why, take a look at the field syntax:
-
SharePoint Form Field:
<SharePoint:FormField runat="server" id="ff1{$Pos}" controlmode="Edit" fieldname="Requester" itemid="{@ID}" __designer:bind="{ddwrt: DataBind('i',concat('ff1',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Requester')}" /> -
ASP FIELD:
<asp:TextBox runat="server" Value="{$Employee}" id="ff1{$Pos}" text="{@Requester}" textmode="singleline" __designer:bind="{ddwrt: DataBind('i',concat('ff1',$Pos),'Text','TextChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Requester')}" Rows="0" Width="0px" Font-Names="Arial" Font-Size="X-Small" Height="0px" />
Inthe SP Form Field I can't specify a VALUE= to preset the field value.
In the ASP Field I can set the VALUE= parameter to a preset value, BUT, note the "TextChanged" param.
Here is what happens:
-
You fill out your custom form, containing both SP and ASP fields.
-
The Values in the ASP Fields are stored locally (not to the DB yet)
-
You press OK or Save or whatever.
-
With no SP validation errors, the values are updated.
-
With SP validation errors, the page RELOADS and shows the errors. When fixed and you click OK or Save or whatever, the TextChanged test says. "Nope, same as when the page loaded (or reloaded after the validation error)" so the data is not updated.
-
If I could find out a different option for the ASP TextChanged, like ForceSave or AlwaysSave or SaveTheD###DataOrIWillRipOutHarddiskAndRunItThroughAWoodChipper, it would work. But I can't find one. (Can you tell that this REALLY bugs me?)
So what I did: (Kind of sucks but works)
Pass the params to an initial NEW form with only the passed (ASP Field) info: (Name, ID Number, Department). State that you are Verifying their information, and they Click OK to continue. This creates the new Item. Pass them directly to the edit for the item using the SOURCE parameter. This way, my passed data is in the DB and it wont be lost if a Validation error occurs.
I would love to know a better way around this.
-
-
Tuesday, April 22, 2008 5:19 PM
Thank you for your reply, and I basically feel the same way about this problem. I have done similar solutioins in other forms. Usually I have found a way to minimize a form to just a few fields and fill in the rest with workflows. This is also good for an easy user experience. However, for this particular form I don't think I can do that. There are just too many fields to enter and I need the SP validation on a people and groups field, and a date picker. I would like the validation on other fields too, but I turned it off to prevent some of the errors.
Do you have any ideas on what to do if you want to make sure the user in the people picker is a valid user AND about a dozen other fields need to be saved?
-
Thursday, May 08, 2008 2:38 PM
Florian,
I got somewhat sidetracked and I'm just starting to work on this again. I noticed that you mention that your ASP controls are what get cleared. For me it is the SharePoint Drop Down controls that will not retain their value. I tried out some ASP Drop downs and they actually lose their value too. I went with the SharePoint Drop downs over the ASP drop downs because the SharePoint drop downs start out blank. ASP drop downs take the first value of the datasouce and if that is what the user wants then they won't select it, and then nothing gets saved to the list.
Also, my SharePoint Form Fields work fine, but if I convert a sharepoint form field to a SharePoint
VDropDownList then that is when I run into problems. I have to do that to bind the drop down to a datasource that filters the list though. I've been messing around with some of the session state and view state stuff but I still can't seem to get it to work. Did you ever have any luck?
Thanks,
Eric -
Thursday, May 15, 2008 3:29 PM
Florian,
I tried changing the EnableViewState property on the drop down to 'false' and this somehow fixed things. This really doesn't make sense why it worked, but it did. If you get a chance sometime will you try changing your view state on the drop down to 'false' and let me know if this fixes your form? Don't disable it on the datasource, just the drop down.
Eric
-
Monday, May 19, 2008 8:35 AM
I have the exact same problem. I have quite a long form and with a new entry when a validation error occurs i cannot save the form.
The form i'm using is build upon a custom list. How would i change the EnableViewState property to see if it solves my problem?
Jacob
-
Thursday, May 22, 2008 8:47 PM
Jacob,
First off, how did you create your form? Did you create it in SharePoint Designer? Did you delete the default form control on the NewForm.aspx (because you shoudn't if you did)? If you haven't customized the form then you will need to do so to get to the properties of the controls.
If you have customized your form, and if you are in SPD, then clicking the drop down box should highlight the code of that control in code view, and should start off as <SharePoint
VDropDownList. Then just change the EnableViewState property to False.If you have not customized the form then check out the following links to get familiar with doing this. I recommend reading the link under 'problem with customizing new form' first so that you know what not to do while setting up a custom form.
Customize the new form:
or
http://office.microsoft.com/en-us/sharepointdesigner/HA101191111033.aspx?pid=CH100667691033
Problem with customizing new form:
http://support.microsoft.com/default.aspx?scid=kb;en-us;935504&sd=rss&spid=11373
Eric
-
Wednesday, October 20, 2010 6:19 PM
I am having this problem too, but I am not editing a sharepoint list. I am using the sql to populate dvwp fields. Some of those fields I'd like to prepopulate and I'd like the form to update all the rows whether or not they have changed.
I have changed all the asp control to enableviewstate = false.
I also tried adding a listform webpart, but again, this is not trying to update a sharepoint list but a custom table. Everything saves to my custom table so long as something about the row in question changes.
-
Tuesday, February 19, 2013 11:31 PM
I also just found out that if you don't want the first item in the drop down to show up as a blank item then delete the property 'selectedvalue'. Leave it if the field is not required and blanks are okay.
So it should look like this if you want the first value to be blank.
<SharePoint:DVDropDownList runat="server" id="ff1{$Pos}" __designer:bind="{ddwrt:DataBind('i',concat('ff1',$Pos),'SelectedValue','SelectedIndexChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Lookup" datasourceid="spdatasource1" datatextfield="ID" datavaluefield="ID" selectedvalue="{@Lookup}" />
And it should look like this if you don't want the first value to be blank, and you want it to retain values after validation occurs.
<SharePoint:DVDropDownList runat="server" id="ff1{$Pos}" __designer:bind="{ddwrt:DataBind('i',concat('ff1',$Pos),'SelectedValue','SelectedIndexChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Lookup" datasourceid="spdatasource1" datatextfield="ID" datavaluefield="ID" EnableViewState="False" />
In my example I display and store the ID of the lookup item. Usually you probably want to display something different, like title or description, so in that case datatextfield would be different.
- Edited by Eric Sammann Wednesday, February 20, 2013 4:03 PM code blocks not showing code

