Project

General

Profile

Help With Adding Fields Based on Select Value

Added by Tide _ over 11 years ago

I am trying to create a new plugin for Redmine. In the new.html.erb form I am trying to change the form fields based based on what is selected in my select box.

Redmine does what I am wanting in the CustomFields >> New Custom Field section of Admin. I have tried to read though the Redmine code but that module is very complex to my rookie Ruby eyes. I have done this using Javascript but it has a side effect. When the form fails validation the generated fields are not redrawn. The user has to select another option then go back to the option they were on in order for the form to generate the fields again. The Redmine New Custom Field does not suffer from this somehow.

This is what I am after:

Default: What is seen when the "Add New" is clicked

Text: What is seen when the "Text" option is selected

Upload File: What is seen when the "Upload File" option is selected

One thing I noticed is the Redmine version puts up a *Loading progress visual in the center of the screen when the fields are being generated. I would like to do this as well.

If anyone could provide me with a simple example of how to do this I would really appreciate it.

In addition if anyone has some insight on uploading files as a Tempfile that would help me on the next part which is implementing the File Upload part. I am guessing saving the file as a Tempfile then dealing with it on the Create action is the best way to go.

Thanks,
Tide


Replies (1)

RE: Help With Adding Fields Based on Select Value - Added by Tide _ over 11 years ago

Got it working. The problem was I needed to pass back some value to new after a failed create.

if @fred.save
flash[:notice] = l(:notice_successful_create)
redirect_to_tab(fred_type)
else
render :action => "new", :params => { :betty_type => params[:custom_flinstone][:betty_type] }
end

Now all I need to figure out is how to get the Loading... ajax-indicator integrated into my plugin.
Any thoughts on how to do this?

    (1-1/1)