can we add form on activeadmin index page in rails 4 - forms

I'm rendering a partial in my index page
index do
.
.
div id: "overlay-select-period" do
render partial: "select_period", locals: { period: GoalCalender.legend_name_year, record: UsersGoalCalender.new }
end
.
.
end
and in this partial (.html.erb) under app/views/admin/users_goal_calendars, I'm having rails form helper form_for used
but when I run the app, it doesn't show the form tag on the view <form></form>
can anyone tell me whether we can add such form in activeadmin index page?
P.S. I've tried all other ways to add form (formtastic, simple form
and form_tag), and writing the form directly inside index do...end
(without rendering a partial) with no luck

I know this is an old question but I just discovered myself that AA somehow removes your form tag if batch actions are enabled.
This is because enabling batch actions wraps most of the page in a form and nested forms are not fun.
The mention something about it here if you scroll all the down: https://activeadmin.info/9-batch-actions.html
I tried disabling batch actions and the form tag comes back.

Related

Drupal 8 form and view in block

I am very new Drupal, In a block I would like to have a form with select box and submit button. Each options in the link is link of content page. That is when the user select an option and click the submit button it will redirect to other node page.
For the above requirement client used Web Form for Drupal 7 and I would like to clone the requirement for Drupal 8. I tried EForm and I am able to create a form but I can not able to show the form in Block Layout and View.
I am not sure the module Eform is suitable for my requirement.
Can you guys please help me what modules do I need to install for the above requirement in Drupal 8.
Okay, I don't know if there are any modules out there which do exactly what you want to, but you can build your own custom solution. In my eyes there are two main possibilities:
create a custom block type with a HTML body field, put your HTML in there and you're done. Advantage: easy to do, Disadvantage: hardcoded
clean way: create a new node type and/or a new category, which you will use for your country nodes. Then you'll create a block programmatically and query for all nodes of that certain country type or for nodes with the "country page"-category, whatever you use to organize those nodes. Then you just create a form out of that data and render it.
Advantage: dynamic, the select list will update itself whenever you add or delete new nodes of that type / category. Disadvantage: takes more effort initially
I personally would recommend using option 2. Option 1 is better for really simple and "stupid" requirements like showing some hardcoded text/image on several places on your site, or if it's something temporary like some campaign teaser, which will be over in 1 week and you'll throw it away after that.
EDIT:
Entity Query: https://api.drupal.org/api/drupal/core!lib!Drupal.php/function/Drupal%3A%3AentityQuery/8
How to build Forms in Drupal 8:
https://www.drupal.org/node/2117411
For display only your block in your templates with preprocess the best way is:
$block = \Drupal\block\Entity\Block::load('my_block_id');
$variables['My_region'] = \Drupal::entityManager()
->getViewBuilder('block')
->view($block);
And in your page.html.twig or node.html.twig or xxx.html.twig use your variable My_region like this :
{% if page.My_region %}
{{ page.My_region }}
{% endif %}
For details check:
https://drupal.stackexchange.com/questions/171686/how-can-i-programmatically-display-a-block

Pass dato between Actions - Symfony 2.6

well I have some problems to pass data between actions...
I have a actions that have a form, this form only have 2 element, a text area and a radiobutton.
well, I need pass the text and choice to other action and show this text and this choice... I try whit manual of symfony but I don't see how to make...
Thanks !

How to send multiple forms with one button in Contao?

I have a question about the wrappers/accordeons. I now have multiple wrappers and in each wrapper there is a form. Now, I want one sendbutton on the end of the page. The sendbutton which will send all the forms that have been filled in at once.
How can I do that?
I don't know why you want to break input into different forms and then submit them again at once. Would it not make sense to use one form and submit the data and process it the way you want using the processFormData hook? may be because you want the accordion to group you form fields. Let me help you this way:
Create your form in the format shown below. Make sure the form has a tabless layout to be able to use fieldsets.
Create a fieldset without a label. You may add the class ce_accordion just in case you have some styling attached to it.
Create a field of type html and add the following markup.
<div class="toggler">Form 1 headline here</div>
Create another field with the following markup
<div class="toggler">
Now create your input fields from here. for example a text field,textares.
Create a field of type html to close html markup created in step 3
</div>
Create a fieldset wrapper end here.
The above steps can be repeated as many as how many groups of fields you want to create in an accordion.
Now create you submit button here and it will send all your data the way you want.
Just a by the way:
If some one submits a form in a wrapper that is closed, how will he know which wrapper has error fields?
$(document).ready(function() {
$(".ce_accordion").each(function(index,el) {
if($(this).find("p.error")){
$(this).addClass("hasErrors");
$(this).find("div.toggler").addClass("active").attr("aria-expanded","true");
}
});
​});​
You can now add a style for .hasErrors rule

Generate subform in ajax call

I have a form with collection of subforms - student with different studies - relation manyToOne. I have corrent database schema and entities and form builder works well. I don't know how to append new "study" object. I need to get html tags from somewhere in either cases - when there is at least one "study: object (clone him) or there is no such a one.
Let's assume that study object has 2 fields: name and year. If for a student there is such a record (object) it's first input in generated form has name "student[study][0][name]". And is surrounded by . When I click "Add new study" button I want to duplicate this surrounding div and change id's and name's of html form elements respectively. Is there ready library or method to use?
But there may happen there is no study records so far. So I need to get form from server through ajax call. Unfortunately returned form has inputs with names like "study[name]". Is it possible to render this form similar to first case - I mean "student[study][0][name]". But i'd like to avoid manually generate twig template for form - I prefer
{{ form_widget(form) }}
You should be dealing with data-prototype rather than issuing separate AJAX request. The whole concept of adding/removing subform items is described here:
http://symfony.com/doc/current/reference/forms/types/collection.html#adding-and-removing-items
Obviously, you will need to some JS (jQuery is highly recommended) in order to replicate subform fields.
You should note, however, that data-prototype behaves differently when you initially have empty or non-empty collection. At least I have encountered this weird behavior. As far as I remember, in first your when you say {{ form_rest(form) }} additional DIV is appended with data-prototype attribute consisting of form's HTML. In second case actual HTML (not as an attribute) is appended with ID attribute "form_name_$$name$$" where you need to replace $$name$$ with proper index.
Now, you really should take a look - maybe all this has been fixed in some recent versions but I can't be sure...
Hope this helps a bit...

How to stop submit of all of fields in a div of a form?

I have divided form in to two sections: sec1 and sec2. Each section is part of a div named as sec1Div and sec2Div. Based upon some selection one of div is hidden. But the problem is that still fields in hidden section are submitted. Please suggest a way so that all of fields in a div are not submitted on submit.
There are several ways to do that. You can hook a function to the form submit's event, or you can remove the name attributes of the fields inside the hidden div. You can also disable the fields, by setting disabled="disabled".
If you are using jQuery, you can do those examples.
To disable all fields in the hidden div, you can do something like:
function hideDiv(el) {
$('input', el).each(function(){
$(this).attr('disabled', 'disabled');
});
$(el).hide();
}
And, the appropriate show div function:
function showDiv(el) {
$('input', el).each(function(){
$(this).removeAttr('disabled');
});
$(el).show();
}
Please remind that this is just a code example. But you can take the idea from that.
The reason this is happening is because the elements are still within the form element. Hiding a div using CSS won't change this - they're still present in the DOM.
It would likely be easiest to add a hidden input field to each div that can be used to identify server side which one you should be processing. You can then simply ignore the data from the hidden form.
If you really must stop the data from being posted, it's a little messy but you could move the hidden div's contents outside of the form element so that the fields won't be submitted. If you wanted to display the div again, you'd then need to move the fields back in. Depending on how complex your CSS is, this could cause problems in some browsers, so I'd advise using my first suggestion.