I have an embedded form collection in Symfony. Which is working nice. I am working with a manytomany assocation mapping.
Except i want to create (with javascript?) the form so that only unique values are available. In my example i have an Organisation which can exist of many users. When i add user "L" in this case and i want to add a second user i want to prevent that user "L" is available in the other dropdown.
The way i embedded the collection of forms is exactly like the documentation of Symfony has learned me. (http://symfony.com/doc/current/cookbook/form/form_collections.html)
Down below is an example of how it works now (in this example I want to prevent that in the dropdown the user "L" is available as an option.
Thank you very much!
Unfortunately, there's no way you can make the HTML form behave this way. HTML forms just do not have any composite (or dependent) <select> widgets. So, the right way to go here would be:
validating the form server-side, so that duplicate values in two select boxes are not allowed;
adding some JavaScript code to the view that renders form. Perhaps this code should listen to <select>s' onChange events, and once an event is received, the option selected in the first box should either receive a disabled attribute or get deleted.
Related
I'm just starting to get into Access due to my job and am tasked with creating a form that displays Data for the individual users on load. Basically what it needs to do is to get data from 3 tables, join them together, and then display the found rows that match that person's accounts they are responsible for managing.
I have this working via a single table Query using a listbox and a datasheet view, however, being a web developer by trade, I would like functionality that displays items similar to what a Unordered List(UL) would display and with functionality that allows the user to click on the company name(which acts as a hyperlink) to then update the information in a new form that I have built, by loading that data into the form, and allowing them to update the fields that I have designated as changeable.
Is this possible in Access via a form or would this be too difficult to implement? I'm decent with VBA, still learning what a lot of the things do, but as far as the logic and things like that to make something happen, I can do that no problem. These rows all have a unique ID so I would be able to either keep them in a collection to populate the form data or I can simply requery the data using the ID number for loading the form data.
A listbox performs like a combobox in datasheet view. Did you mean you have a combobox?
Actually very simple to accomplish, and various methods available. I assume you have a form bound to your Query with a combobox that lists companies. Controls have events. Use the Click event of the Company control. I use only VBA (not macros but macro could do this). Select [Event Procedure] in the event property. Click the ellipses (...) to open VBA Code Editor, type code into the procedure:
DoCmd.OpenForm "CompanyInfo", , , "ID=" & Me.tbxCompany
Keep in mind, controls used for the purpose of entering/selecting filter criteria should be UNBOUND, otherwise you would change data in record. However, using the Click event of a BOUND combobox (as long as you click on the box, not the dropdown) or textbox will not change existing data, not so for a listbox.
I am looking for best practices on SYMFONY FORM handling to achieve the following standard page (surprisingly I haven't found anything similar existing yet on SO).
Here is a shema of what I want to achieve:
As you can see at the top there is a SYMFONY FORM to filter the results that should be displayed.
It displays a table and each tuple of the table should permit to open another SYMFONY FORM kind linked to the tuple.
I am in the process of learning SYMFONY FORM, so far, I can manage to create the top row FORM to set the filter that'll apply to the table display.
But I wonder if anyone has experience on the second part: Displaying the table that embed as well many forms of a similar kind -That seems a bit more complex. I read about TWIG.EXTENSION and FORM.COLLECTION, I'll investigate that. But if someone could save me to re-invent the wheel and lead me to some direct shortcut, I'd be really grateful.
No idea if it's the best practice, but one way to do it would be to create a new property for your entity being listed in this table, called $editionForm (without mapping it to the database) for example.
Then, either throught a custom loop or by listening to a doctrine (or any ORM you use) hydration event (or triggering such an event if you don't use any ORM), fill the property with the generated form, probably within a dedicated service.
Then, just use it in your template like this :
$entity->getEditionForm()->render()
I am a Django noob and have a situation that goes beyond the basic documentation, etc.
I am updating an ordering webpage that has a form structured as follows:
several text boxes, etc to gather general info (name, date, etc)
two separate tables for selecting (via checkbox) catalogs that are generated/managed using endless_pagination. Each table can have thousands of records, hence the endless_pagination. The first column in each table is a checkbox with value = catalog.id.
a textbox where the user can manually enter catalog IDs
a submit button
I am not sure how to keep track of what a user has selected in the two paginated tables since the checked boxes are lost when choosing a different page. Also, when the user flips back and forth between the pages, the previoulsy checked catalogs will need to be re-checked(since the checked state is not maintained). I am also not sure which tool(s) to use to deal with this.
My thought is to use JavaScript (with which I have minimal experience) to update a list of catalog IDs whenever a checkbox is checked/unchecked and:
- and attach that list to the form or
- update a variable in the form or
- send as a variable separate from the form, whichever is possible/makes more sense.
I'm hoping that maintaining a list of catalog IDs is possible because the next iteration of this form will likely include some sort of filtering so I'm trying to devise a solution that will not have to be reworked later.
I have reviewed a lot of posts but I believe the closest solutions are rendered useless because of the endless_pagination.
Let me know if further clarification is required. Thanks in advance for any suggestions.
UPDATE
I tried using JavaScript to store the catalog IDs in an array when a checkbox is checked. This does not work when a user selects another page in the pagination. The array of checked catalog IDs is lost when the page 'reloads'.
I'm running into this problem right now as well. I'm handling this by writing the checked items to localStorage so they carry across to page 2, 3, etc.. as well as show up as already checked when you go back to page 1. Then every time the page loads, either find and check the existing checkbox, or create a hidden input with the appropriate name and value and append it to the main form.
var selected_items = []
function add_item_to_checkbox(item) {
localStorage.setItem('selected_items', JSON.stringify(selected_items));
checkbox.on("click", add_item_to_checkbox);
bahh... Just look at my jsfiddle it's easier to read and yeah. I don't have to type JS into a textarea on stackoverflow.
Here is my javascript minus a few things that are specific to my code. I'm sure it could be improved upon but it works really well for my application.
Actually, I can assign a task to a user in the edition task. I display a dropdown list of all user in the system when I edit a task. Now, I would to be able to display a text input with autocomplete for user, and be able to add user if is not exist.
How to do that?
Thanks in advance.
Two things you need to do:
1) Create a Data Transformer
hich will let you use an input field instead of the default dropdown to the linked entity.
The Data Transformer basically transforms your input (in your case a username string) to actual user object that you can store with your entity. It will let you define an input field instead of the default dropdown to the linked entity. Have a look at the documentation, it's pretty straight forward.
2) Create the Ajax autocomplete
This can be done using any library you want (jQuery, Prototype etc.) on the client side, and server side you handle this in your Controller action and replies with either JSON or a rendered template. There are plenty of tutorials for this out there. The Ajax result could include a link to create a new user, if none is found.
The Data Transformer is what you need to focus on, and I would get that working before working on the UI.
Basically, what pros/cons are there to using multiple forms in the same web page vs one form with multiple submit buttons? Any difference at?
Ah? Multiple submit buttons on a single form will all submit the entire form when pressed... there's really no advantage to having multiples, unless you're overriding how the submit process works so each button only submits it's own area. In this case they'd probably not even by submit buttons, but just buttons with sum JS code to handle submission.
Multiple forms are discrete spaces of data collection, each can have it's own submit button... but only one of them can be sent at a time (and depending on the browser you may loose what's in the other forms).
Neither approach is particularly good from a user interface perspective since it'll be confusing.
The real question is, what are you trying to do that prompts you to ask this?
The two behave differently and there are good reasons to choose one over the other.
Multiple Forms on a page allow you to send data to two different locations. A common example is to have an input form as the main focus of a page going to one location, and a search form that appears as part of the generic header/footer. These both go to separate locations and submit only the HTML form elements within their appropriate <form/>
Multiple submit buttons offer you the ability to give different purpose to a submitted set of form elements. E.g. One form may have a bunch of submit buttons all with name attributes, meaning you can add conditional logic on the server side to say: "Continue", go " Back" or even "Save for later". All reference only the form elements within it's parent tag.
Two side notes are: 1) You can't nest forms. 2) JavaScript can change this default behaviour if you wanted it to. :)
Edit: with reference to a comment you made, if you wanted to do without JavaScript (a wise choice while it's not needed), you could do some careful thinking and keep POSTing the form to itself. Each time checking which form button has been clicked (top tip, give them all the same name and you can just switch case through it) and do whatever you need to do, including performing validation. E.g: When they hit "add media", you'd save the media uploaded and return a reference of it to the screen as a hidden input. The user can then continue to add things to the other boxes and when complete, hit your save button, at which point you do all the main saving work and make sure you tie the uploaded file to it as well.
You effectively keep adding stuff to their screen until they hit the save and then you perform a save method and redirect to a thank you page (or whatever logic suits your scenario). :)
All fields in a form are sent when one of their submit button is clicked. It's for you to see if you need all fields or not.