last day (17 days later) » 

4:01 PM
1
Q: CRUD Operation Not Updating One Field

RCarmodyI am trying to add a new column to my User form called stakeholder_quadrant, but I am running into weird scenarios. 1) when I create a new item, it does not actually save the value that i enter in this field, and 2) when I go to update an item, the form pops up with stakeholder_group&stakeholder_...

 
Hi, your modal(new) doesn't have any input with name="stakeholder_quadrant" there are two inputs with same name i.e : stakeholder_group ?
 
Yes I fixed this but no luck
 
Try printing values which are getting passed to your backend page inside your submit handler see if all values are correct
 
@Swati - confirmed that I am able to update the field from the command line as well as within my SQLite3 database. This must mean that my models are working, so the issue resides in either my views or js portion of my code, correct?
 
yes .. just put alert(stakeholder_groupInput +","+stakeholder_quadrantInput) inside your $("form#addUser").submit(function() { see if that showing right values
 
4:01 PM
Just added an edit to the post with the details. Adding that alert did not trigger anything unfortunately... Maybe I added it in the wrong spot?
 
Your page should not get refresh because here you need to use ajax so first handle that issue . Check this post to avoid same and then let me know further update.
 
I've added this code (updated above) based on the link you shared but no changes: $(document).ready(function() { $('form').on('submit', function(e){ e.preventDefault();
 
Hi, so still page refreshes ?
 
Hey, yes. The page refreshes and updates the url while not actually creating the record
 
ok ..alternative way ..change type="submit" to type="button" then change your handler as well using click ?
try that
 
4:10 PM
<button class="btn btn-primary form-control" type="button">SUBMIT</button>
<script>// Create Django Ajax Call
$(document).ready(function() {
$('form').on('button', function(e){
e.preventDefault();
Updated 'submit' to 'button' in these two spots
Now, when I hit submit the form doesn't actually submit. The modal does not go away and the values remain
 
$('form#addUser').on('click','[type=button]' , function(e){ <-- like this
 
$(document).ready(function() {
$('form').on('click','[type=button]', function(e){
e.preventDefault();
No change... submit does not do anything
 
put alert("in"); see if that gets call
 
$(document).ready(function() {
$('form').on('click','[type=button]', function(e){
e.preventDefault();
alert("in");
var employeeInput = $('input[name="employee"]').val().trim();
var descriptionInput = $('input[name="description"]').val().trim();
var stakeholder_groupInput = $('input[name="stakeholder_group"]').val().trim();
var stakeholder_quadrantInput = $('input[name="stakeholder_quadrant"]').val().trim();
Am I placing that in the right spot?
 
4:23 PM
I just copy pasted the code and then added '{% url 'polls:crud_ajax_create' %}' into the url piece but still no luck with the button
 
not showing alert like in fiddle ?
 
The second pic is how far I get... I click on that button and nothign changes. The button recognizes being clicked but no action
 
okay do you know how to check ajax request ?
also you mean alert is showing ?
 
No alert showing
Not sure how to check the AJAX request - is that through the command line?
 
are you using chrome ?
 
4:33 PM
Yes
 
first check your browser console
right click -> inspect -> console
see if there are any errors
then ,right click -> inspect -> network tab ->XHR (to check ajax call)
do above after clicking that button
okay i have to go now .. its to late here so ..
 
where is 490 line ?
 
I don't know... I dont have any code that is 490 lines long
My HTML for this page is 450 lines
(including js)
 
also you are getting 403 error ..
check network tab
 
4:39 PM
Two requests:
{itemsReceived: 1, itemsAccepted: 1, errors: []}
errors: []
itemsAccepted: 1
itemsReceived: 1
 
okay try debugging ..more .. i have to go now :)
will come tomorrow
 
Thanks!
I appreciate the help
 
let me know further update
also about that 490 line click on that it will show you where it refers ..in you code
good day :)
 

  last day (17 days later) »