So I have now added some data to the "rescind emeritus request" button [1].
This data is the file name from the emeritus_request, and it is also now data
available to the submit function. (If there is a better way to do this, please
let me know.)
The data is read in the submit function [2]. But it doesn't work. What is the
right way to send additional data fields in the POST request? I have verified
via the console log that the data (emeritus_file_name) is proper, but I get an
exception trying to put it into the formData.
TypeError: undefined is not an object (evaluating 'formData.push') line 371
What I'm trying to do is to have the file name available to the memstat.json.rb
file that handles the POST request. Is the entire committer transmitted on the
POST, or just the few changed fields?
Thanks,
Craig
[1] if (owner)
if committer.member.status.include? 'Active'
emeritus_file_name = committer.forms['emeritus_request']
if committer.forms['emeritus_request']
console.log('owner emeritus file is: ' +
committer.forms['emeritus_request'])
_button.btn.btn_primary 'rescind emeritus request',
data_emeritus_file_name:emeritus_file_name,
name: 'action', value: 'rescind_emeritus'
else
_button.btn.btn_primary 'request emeritus status',
name: 'action', value: 'request_emeritus'
end
elsif committer.member.status.include? 'Emeritus'
_button.btn.btn_primary 'request reinstatement',
name: 'action', value: 'request_reinstatement'
end
[2] # submit form using AJAX
def submit(event)
event.preventDefault()
form = jQuery(event.currentTarget).closest('form')
target = event.target
# if (cancel) button is pressed, don't submit but remove @edit form
cancel_submit = target.getAttribute('data-cancel-submit')
if cancel_submit
# remove the edit buttons and return
@edit = nil
return
end
# if additional data, add it to formData
emeritus_file_name = target.getAttribute('data-emeritus-file-name')
console.log('submit emeritus_file_name: ' + emeritus_file_name)
if emeritus_file_name
371: formData.push name: 'emeritusfilename', value: emeritus_file_name
end
# serialize form
formData = form.serializeArray();
# add button if it has a value
if target and target.getAttribute('name') and target.getAttribute('value')
formData.push name: target.getAttribute('name'),
value: target.getAttribute('value')
end
Craig L Russell
[email protected]