mcintyre321 / FormFactory

MVC5, Core or standalone - Generate rich HTML5 forms from your ViewModels, or build them programatically

Home Page:http://formfactoryaspmvc.azurewebsites.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Asp.net Core 2.2: Nested forms not working

the-jos opened this issue · comments

commented

Hi,

I just spent a couple of days getting to know FormFactory. I'm almost there for my class project, but I seem to run into a bug that I can't seem to fix. As a test I copied the code for NestedFormsExample2 and it shows the same problem as what I put together:

  • Nested textinputs for non-default selections are rendered as readonly. In NestedFormsExample2 this means that anything besides the Facebook Name input is grey.
  • On pageload 'No Contact' is selected but it incorrectly shows the Facebook fields underneath. Selecting another option resets/fixes this. I tried several jquery versions as I saw suggested in another issue here but that didn't change anything.
  • Most importantly: the only fillable facebook string returned is null.

I've read every issue but didn't see anything that could help. You can easily test it by creating an empty project and trying it for yourself in Core 2.2. I just pushed my NestedFormsExample2 Test, you can check it here: https://github.com/the-jos/FormFactoryTest/

Another problem: there seems to be something wrong with the resources. I added the lines in startup.cs but the ICollection-buttons don't appear for example. I tried with your template nuget but it doesn't compile, it shows errors. That nuget also dumps a lot of files in the root of my project, I don't think that's intended?

One more question: is nesting of ICollection supported? I saw a discussion (#62) that said the issue with selecting parents was fixed? I get errors on that as well in the console (Uncaught TypeError: Cannot read property 'id' of undefined. FormFactory.js:168)

I was hoping to take a shortcut by using FormFactory but our class deadline is fast approaching. I'm not very experienced so I may be doing something wrong. However I'm pretty certain that something's up.
Last thing: on your main page the InhertitanceExample code section is showing an error loading the code from github.
Thank you for this very interesting project and any insights you can share would be appreciated.

Edit: added my own FormFactory attempt in my Test project under Models/Create and MyForm.cshtml. It's intended as a Surveybuilder.

Hmm, there's definitely a bug. In the view:source for your page it's rendering


<select class="ff-choice-picker form-control" FormFactory.PropertyVm.Disabled() >
--
  | <option value="0">No contact method</option>
  | <option value="1">Social media</option>
  | <option value="2">Phone contact method</option>
  | </select>


Instead of FormFactory.PropertyVm.Disabled() it should be conditionally rendering a disabled attribute.

One of the option elements should have a selected attribute

I think thats a brackets issue at https://github.com/mcintyre321/FormFactory/blob/master/FormFactory/Views/Shared/FormFactory/Property.System.Object.cshtml#L27

And I think there's an issue rendering the selected value at https://github.com/mcintyre321/FormFactory/blob/master/FormFactory/Views/Shared/FormFactory/Property.System.Object.cshtml#L31

I haven't got the time to look at this for a few weeks, but if you want to get it working, I would copy FormFactory/Views/Shared/FormFactory/Property.System.Object.cshtml into your application (sorry the Template project didn't work!) and fix the changes there.

If you are feeling like a really good person you can send a PR with the fix!

commented

Thanks for answering so quickly!

I played with it all afternoon but didn't succeed in copying the file you mentioned: am I doing it wrong? I found the file in the assembly and copied it to the project's own Views/Shared/FormFactory folder, but changes I make in there aren't picked up by the application. If you guide me a little I may succeed, but messing with libraries (and overriding files within them) is out of my skill set right now. I even tried to add a reference to a downloaded version of FormFactory but I pretty quickly gave up on that. If I could get my copied cshtml file to be recognized I think I'd stand a chance as we've heavily been studying razor and js this year. Am I supposed to do something with the namespace maybe? I'm kind of lost, sorry.

Hi, I think I should be able to send a fix for this later this evening if you are happy to wait.

I've pushed a new version, and you can see the example working at http://formfactoryaspnetcore.azurewebsites.net/

However, your sample project doesn't seem to work correctly after I update it. The 'PhoneContact' options are all disabled, but I'm not sure why...

commented

I played around with it last night and this morning. It thought it could be related to the imported scripts versions and load order. I think right now my example version has the same scripts and load order as your main site. I've updated my FormFactoryTest code on Github.

Unfortunately I did not succeeded in enabling the PhoneContact fields of your example. Occasionally the disabled problems returns in the first shown Social media fields and a page refresh fixes it. However anything typed in any input will still return null to the post method.

My script changes didn't do much to my own Create Form example either: the QuestionType/Question field still stays grey for anything besides the first option in the CreateQuestionViewModelType_choices() method. Trying to drag one of the (nested) questions or options still causes undefined id & parentelement errors. I did solve the button icons not showing though (with prettify).

Something else I noticed while playing with the scripts: in Chrome the console doesn't show any errors, but in Firefox it shows about 50 of them, related to css, most from bootstrap, a few from FormFactory. I saw you have the same errors on your main page in Firefox. Maybe ff is just more verbose, I don't know.

Strange - I'm only see seeing
image

in FireFox at http://formfactoryaspnetcore.azurewebsites.net/

commented

That's strange. Look at this:

image

commented

I think you can safely ignore above errors: I tested your site with several other computers than my laptop with FF and nowhere else do I get these errors.