I'm trying to create a collection_action in ActiveAdmin which allows me to Import a CSV file and generate Subscribers from it. I want to be able to click an action_item link and be taken to a form in which I input the CSV file, and then do some work with it.
This is what I have so far:
ActiveAdmin.register Subscriber do
collection_action :import_csv, :method => :post do
render "import_csv"
end
action_item do
link_to "Import from CSV", import_csv_admin_subscribers_path
end
The view is also created, just blank at the moment. I've restarted the rails server, and rake routes outputs:
import_csv_admin_subscribers POST /admin/subscribers/import_csv(.:format) admin/subscribers#import_csv
batch_action_admin_subscribers POST /admin/subscribers/batch_action(.:format) admin/subscribers#batch_action
admin_subscribers GET /admin/subscribers(.:format) admin/subscribers#index
POST /admin/subscribers(.:format) admin/subscribers#create
new_admin_subscriber GET /admin/subscribers/new(.:format) admin/subscribers#new
edit_admin_subscriber GET /admin/subscribers/:id/edit(.:format) admin/subscribers#edit
admin_subscriber GET /admin/subscribers/:id(.:format) admin/subscribers#show
PUT /admin/subscribers/:id(.:format) admin/subscribers#update
DELETE /admin/subscribers/:id(.:format) admin/subscribers#destroy
However when I click the action item I get the error Couldn't find Subscriber with id=import_csv
If I change the method to :get it renders the view fine. I'm assuming the problem is my use of :post? Is it not possible to render a view if you're calling a controller action with that method?
edit Ok, yeah, it doesn't make sense to render a view with a post but then why does the ActiveAdmin doc suggest that you do the action this way for CSV imports? How are you supposed to # Do some CSV importing work here... without generation a form?
You need to add the method: :post option to the link to invocation, since there's no get action for that url.
Related
my simple view file
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
?>
<?php ActiveForm::begin()?>
<?=Html::submitButton('something')?>
<?php ActiveForm::end()?
Clicked the button. After I reload the page and browser shows me
this
So how can I remove this?
This problem happen when you submit data in a form and then refresh the page
Browsers should stop this, or at least prompt if you want to resend the data,
but the best way to prevent this from happening is submit the data .. and manage the submit properly.
In you case your submit repeat the index action because you don't manage proper the action code
(all you're being made does not produce the creation of a new model to be complete so as not prroduce displaying a result.
or any other action ..
your code continues to call the same action that produces post calling for action and so on)
try adding a simple die() or a render for another view
public function actionIndex()
{
if (Yii::$app->request->post('submit')==='my_value') {
echo "Button my_value Clicked";
die(); // or render a proper view
}
return $this->render('index');
}
This is basic browser behavior. Your form is doing a POST request and obviously when you try to refresh it will ask for this. Even if you write a basic html page without yii, you will still have this.
I am using the external module, NGM Forum.
In thread create form the Save button is not inside the <form> tag.
So when I press save it's not submitting the form.
How can I get the Save button back inside the form?
Please refer to the attached images:
Placement.info
It could be that you have customised the form somehow with your placement.info file and moved the save button down.
Edit form on create form?
Looking at the code from your screenshot it looks like you are on the /Create/ action, and your form tag confirms this with the id="thread-create". Code.
But the Save button is for the Edit action with submit.Save.
You must have made some mistakes with your changes before this point so you will need to explain how you built this form further I think for anyone to help you resolve it.
I'm working with Request Tracker and I would like to add a button when you visualize an open ticket that triggers a POST call to an external Java Server and it returns a PDF file with a report about the ticket. What is the best workaround?
There are many different ways to add this sort of customization. The easiest might be to write some Javascript to add the button by looking at the divs and ids RT writes to the ticket display page. You can drop the Javascript right in the styling box on the Theme Editor page.
If you can request the PDF via GET, you can just add a link in the Links section. Or, depending on what you're trying to do, you can also do dynamic things with custom field values as described in the External Custom Field docs.
I'm trying to validate a multipart form using the jquery validateEngine plug in.
I can validate the form correctly for all fields however I want to take it one step further and use the built in ajax validation.
I want to check whether a name is unique compared to a database. This function works correctly and I get the expected results however I am unable to submit the form and by running validation in firebug console on the form it validates as false even though all fields are correct.
If I remove the ajax validation the form validates correctly so somewhere in this script a false flag is being set but I just don't know where to look or over ride it
The validation is initialised by:
if ($.validationEngine) {
form.validationEngine();
}
and as I say normal validation works.
I've set up the class in my form as:
class="input validate[required, ajax[ajaxNameCallPhp]]"
The script in the validation engine relating to this method has been changed to this:
"ajaxNameCallPhp": {
// remote json service location
"url": "http://localhost/greenFees/includes/lib/greenFee/checkName.php",
// error
"alertText": "* This name is already taken",
"alertTextOk": "* This name is available",
"alertTextLoad": "* Validating, please wait"
},
Any help appreciated with this issue
Ok - managed to get this to work after a few hours logging the script in firebug...
Anyway. The culprit of sorts is partly do do with another script - form wizard which turns a form into a wizard, it adds a next button which on click runs the validation. For some reason the validation when called from there behaves differently to the form submit.
With the ajax validation it displays a flag if the nameis ok, if it's already used or a notice when validating.
Solution 1:
Remove the wizard script but then the form doesnt behave correctly
Solution 2: remove the notice alertTextLoad - it appears the validation is treating the presence of this flag as an error rather than info - removing it meant I can keep the wizard
Ta
Does anyone know the syntax, or the way to redirect a sharepoint "New Item Form" to a URL and pass values from the form as parameters in the URL?
So if the form as a "lastname" field, I would want the redirect to be something like http://path_to_other_page?name=lastname
I know I need to use something like:
onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit;__redirect={path_to_other_page.aspx?name=',/dsQueryResponse/Rows/Row/#LastName))}"
Except that's not working for me - I think the "/dsQueryResponse/Rows/Row/#LastName" is not correct - I was just trying to guess from other posts I had seen here...
Anyone?
That looks like something that would work on an edit form rather than a new form - that data is loaded when the page is loaded, not when it is submitted. To get the data in javascript you will need to access the textbox directly - jquery may be helpful.
I think you can use the SharePoint's build in Modal dialog (http://msdn.microsoft.com/en-us/library/ff410058(v=office.14).aspx). Within the modal dialog, you can callback function that will get the parameters from the form page.