Is there a flexible way of creating an "adaptable" form using jQuery?
I've got a requirement to build a 开发者_运维技巧form. The user would like to complete the form in a linear way, with the form adapting to their choices as they're made.
I could do this as a series of if/else statements in jQuery with some onChange events. However, this could become tedious. I was wondering, is there was a pattern/best practice for this scenario?
I guess it would be almost wizard-like, except the form fields would vary depending on their selections... perhaps ~3 stages.
I just spotted this in another question and thought it might be sort of what you're after... I've not been able to have much of a play with it yet though, so i'm not 100% sure!
jQuery.wizard
I would separate the form fields in differents "zones", each with a unique ID, with the initial ones visible and the rest hidden.
Then, every time a form element change its value (bing only one event listener to the form and find the element which generated the event each time to avoid useless event listeners) I will show a new zone, based on the form element the user changed and, if necessary, checking the new value the user set for the element and acting accordingly.
Or you could just have a form with only the initial elements visible and nothing more, then load the content dinamically with AJAX every time a new zone must be showed.
精彩评论