kjac / FormEditor

A form builder editor for Umbraco 7 - let your editors build forms easily with this free package.
MIT License
99 stars 42 forks source link

Cant seem to auto-fill more than 2 fields. #206

Closed kieron closed 5 years ago

kieron commented 5 years ago

Sorry this isnt strictly an 'issue' but im just using the package, and following this, I was able to get Name + Email auto-filled, the same as the guide, but then I added a third one, seen here:

var formModel = Umbraco.TypedContent(1275).GetPropertyValue<FormModel>("form");
                    var allValueFields = formModel.AllValueFields();

                    var field = allValueFields.FirstOrDefault(f => "name".Equals(f.Name, StringComparison.OrdinalIgnoreCase));
                    if(field != null && field.HasSubmittedValue == false)
                    {
                    field.SetSubmittedValue(userName, Model.Content);
                    }

                    field = allValueFields.FirstOrDefault(f => "email".Equals(f.Name, StringComparison.OrdinalIgnoreCase));
                    if(field != null && field.HasSubmittedValue == false)
                    {
                    field.SetSubmittedValue(userEmail, Model.Content);
                    }

                    var field = allValueFields.FirstOrDefault(f => "manager".Equals(f.manager, StringComparison.OrdinalIgnoreCase));
                    if(field != null && field.HasSubmittedValue == false)
                    {
                    field.SetSubmittedValue(userManager, Model.Content);
                    }

I also have in the Form content, a text-field, called Manager, where I have tried uppercase, lowercase, space with an extra word etc, but I keep receiving this error; pic here also

 var field = allValueFields.FirstOrDefault(f => "manager".Equals(f.manager, StringComparison.OrdinalIgnoreCase));
Line 81:                     if(field != null && field.HasSubmittedValue == false)
Line 82:                     {

Thanks in advance!

I have tried naming the field different things and changing the code but just cant seem to get it to go.

kjac commented 5 years ago

Hi... I see a few errors in your code.

  1. You can't declare var field twice.
  2. f does not have a manager property. You're looking for the Name property when you do that kind of comparison. That's why the name and email fields both work.