How to add JavaScript code to Laravel for BackPack? - javascript

I'm using Laravel BackPack to expedite my CRUD webapp.
I have a form with a dropdown list of users.
When a user is selected from this list, I want to populate a text box on the same form with the username of the selected user.
I normally use JavaScript to query the table and return the JSON result.
The returned data is used to populate the #username text box.
I am not sure where to add this JavaScript code in BackPack.
Thanks for your suggestions.

I recommend you create a new field type, starting from the select2 field (or whatever you're using now), and add your JS there.

Related

Make edits on dynamically loaded data using jQuery and PHP

I have a dropdown, on its change I need to load the contents related to it on the same page. Which I did using jQuery. Now the question is how do I make edits on this data and store it on my database. If I am wrong in using jQuery for loading my data then what else should I use? I am using PHP as my server side scripting language.
More detail -
Simply taking there a list of details I need to display as per the country you select, which I am displaying currently in a nice grid(textboxes)!
Now the data from this grid should be copied to another textbox on "EDIT" button click from where I edit them and store it in my database. I am not able to make the values copy into a another textbox
You could do this:
Display the data in some form of editable div, textarea, or other element.
Make a hidden field somewhere and when you display the data
Set the row id from your database to the hidden field
On your change event, grab the id from the hidden field along with the edited data.
Using Jquery/ajax, send that data to a php page that will save thee data to your database using the passed in id.
You could do that.
However, if it were me (and if you're not married to your current databse / mySQL etc..), I would use parse.com. The service is free up to a significant amount of usage (which Ive never come close to) and it really simplifies everything. See the below post if you're interested in that approach:
Save and retrieve user input from database with javascript?

Populating the form

I have a little form with php and javascript. It's a simple form with radio buttons and a couple of text boxes. Under the form there's a table , which is showing the values from the DB.
The php is taking the values of the text boxes and radio buttons and creating a special URL, which is the "Forwarder" in the picture below.
Now when I press the "Edit" button in the table, it must populate the current record with the values of text boxes and radio buttons into the form, so I can edit the values, creating another URL and update the record. The problem is, I don't know how to do it. There can be many records in the table. I don't know how to populate the form with the current record values. And I can't create a table in the DB for each of the values either.
Please can anybody give me some advice ? I will be very thankful.
Thanks beforehand.
On edit click you can run a select query based on the ID of the record. I see you are displaying it, so just grab the text of the ID field from the table. And we assume you have already saved the data from the form above...
Just create a page that gathers the information, and input fields to the table. I'm not sure if fields are static or not, but just populate all the fields manually.
Then have form set to GET type and on submit will be sent by url to the handler page where you could have Query String with PHP so for example index.php?title=TITLE&field1=VALUE
then use $_GET['title] and $_GET['field1'] to grab the information, grab them fields and save back to database.

Grails Dynamic Form Fields

I want to do something like below using Grails:
I can achieve the simple text field using jquery/js. However I need to add the dynamic form field for dropdown list and use Grails gsp tag. But I can't put something like:
var line = "<g:select/>";
in the javascript to add a row. Because there i no GSP engine for javascript.
Also for deleting a row, there is no id in my project, so not quite sure how to delete a row using dynamic form fields.

Suggestion needed for NON JavaScript version of an input autocomplete

I'm building an App that is heavy on jQuery. Most of it I can handle without the use of JS and still have a functioning site, however there is one bit that is eluding me. (note, I'm using ASP.NET MVC but that shouldn't matter in this instance)
I have an input field that is making great use of jQuery-UI AutoComplete. The behavior is very simple. The user is asked to input their City, but is given an AutoComplete list of valid cities. If the city is invalid, the server side validation fires and tells them to try again.
If they do select a valid city, the jQuery method updates a hidden field that contains the CityID of the selected city. This is working phenomenally well, and I really like the performance.
Here's where the problem enters. If JS is not available in the browser, the ID field is not updated, and hence the DB is not updated. I am not using the AutoComplete input on the server side at all, just the ID field. What would be a good solution to circumvent this issue?
Default to a select element containing the cities as options and id's as values, and change it to the autocomplete field with the script on page load.
If for some reason sje397's answer doesn't work for you (it's an elegant solution, unless the city auto-select is based on some other field on-screen, such as a zip code or state), simply POST both fields. When evaluating the POSTed data, if the CITY text box has data, and the hidden field does not, then evaluate the entered city using the same validation method used by the jquery callback. If the hidden field has data, you assume that javascript is enabled and use your current logic.
Several options:
1 - Serve HTML initially that shows the "hidden" input, and doesn't include the "autocomplete" one. When JS loads, have a function edit the DOM to your current situation.
2 - Have the form default to send the "autocomplete" data to the server. Use javascript to edit the "send" function to have it switch to the "hidden" input.
Get the page to by default to send the input of the user over the intertubes to your server, if javascript is enabled, change it so it only sends the ID over instead (using javascript obviously).

Dynamically populating an ExtJS HTML editor

So I'm using ExtJS for a job I'm working and I'm trying to dynamically populate the textarea associated with the HTML editor with data based on what a user selects from a combo box. From what I've found, I can load the HTML editor with text using the defaultValue property. So if I'm going to populate it after the page loads, can I give it something like a datastore or is there a method I can call to set the text?
Just call foo.setValue("bar");, like with all form inputs.
http://www.extjs.com/deploy/dev/docs/source/Field.html#method-Ext.form.Field-setValue
http://www.extjs.com/deploy/dev/docs/?class=Ext.form.HtmlEditor

Categories

Resources