« first day (1629 days earlier)      last day (3318 days later) » 

6:00 PM
{"address1": "### Name St", "zipcode": "55555"}?
 
Hopefully what ssube said and not that array.
 
just a returned 0-indexed array from the external file
 
welp, you're fucked
 
hehe
 
is it really so bad to do that?
 
6:00 PM
that is, there's no reasonable, reliable way to handle that situation
 
yup.. but.. you could build the <input>s form the array instead of the other way around lieke you are
for each array element, append input, set value
 
Huh, what the heck; just got 30 points in the last 24 hours on a question I answered 8 months ago.
 
but then i'd be generating static elements dynamically instead of just storing the html of the form in cache :x
 
if you need to make the html ahead of time, go back to my 'id' idea.
$('#addressLine1Input').val( shittyData[0] );
$('#addressLine2Input').val( shittyData[1] );
$('#cityInput').val( shittyData[2] );
 
well, getting a bit of a hostile vibe now :/
 
6:04 PM
Just store an array of your values and map it to the corresponding inputs in another object and pray to superman the order never changes.
 
sarcastic vibe since having to get data as an array sucks
didn't mean to be hostile to you.
whoa.. we pray to Batman around these parts.
 
Batman has no powers. He's a second grade super hero. He's just a hero.
 
okay, how about this. let's talk about the overall concept here. maybe you'll show me the light on how to actually approach this thing
 
Return your data as json
 
i'm working on a single page application, only allowed javascript, jquery, php and bootstrap
have to display a variety of different information and have those be editable in different kinds of forms
structure of forms are highly unlikely to change due to the business objectives
 
6:08 PM
!!google php return query as json
 
the network is in the shitter too so aggressive caching is needed
 
Start with returning the data in a sane way if you can
 
user1596138
Aggressively cached data
 
user1596138
i.e. static content?
 
6:09 PM
@Jhawins you have to yell at it. Caches better ;)
 
cache it like a red-headed step-child.
 
it's very data driven
like on the order of 30+ calls to DB/page
 
Are you reading the links caprica posted?
 
Yeah, i'm familiar with returning JSON from PHP
I'm using it in a few other places for multiple values in select boxes and whatnot
inheriting a project like this sucks
so, say we're just doing this while ID thing, i'd just do $("#id").val(data["whatever"]) ad nausem on every single form
correct?
 
You need to. You say that your forms need ot be static. Like your address is predefined, right?
and your input is some array that may/may not be in the same order as the fields on the screen.
 
6:15 PM
sure
 
you'll need to map the array values into inputs.
 
hm, i'm starting to see the point here
 
ids are the straightforward way to know which input you MEAN.
 
a change in the form necessitates a change in the order of the array
but doing via id means swapping stuff doesn't affect the returned data
 
Right.
 
6:16 PM
I would do $("input").forEach(it => $(it).val(data[$(it).attr('id')]));
approx
 
@ssube wait what :O?
 
seems like this would have been a decent idea for stuff that'd never change and/or stuff worked on after i laugh my way out to another company
 
morning
 
@BenjaminGruenbaum jQ6: it's an evil, evil thing
 
ssube's code requires a hash, not array
 
6:17 PM
@ssube why the .attr :(?
 
@BenjaminGruenbaum because I've never had to get the id from the element
unless you're suggesting just it.id
 
insert peter griffin css meme and replace it with js Why does this refer to window instead of Builder in here?
 
@ssube $("input").forEach(it => $(it).val(data[it.id])); but it gets even simpler.
 
how can it get simpler than that?
 
$("input").val(function(){ return data[this.id];}) //works iirc
 
6:19 PM
Sorry proper link with reduced click to see the actual code jsbin.com/lelovejoni/1/edit?js,output
 
@PeeHaa becasue when you do this: new Preflight(builder.do); you are passing a reference to do(). That reference is this called without the "builder" context.
 
okay, what would you suggest for two same forms but different contexts with the possibility of both being worked on at the same time?
 
@BenjaminGruenbaum shouldn't that be attr "value", if attr works at all?
 
ie, a billing and shipping address edit form?
 
he wants to fill in a form
 
6:20 PM
@PeeHaa the 'this' context depends on how you CALL a function.
 
something with fire, i'm sure
 
@ssube oh, sorry, val
 
@Luggage unless the function has been bound
 
@Luggage God this javascript thing stinks
How do I fix it? :)
 
simple fix: new Preflight(builder.do.bind(builder));
 
6:21 PM
oooohhh I can do that
 
assuming your JS environment has .bind()
 
would you just say kill the billing address form if the shipping address form is being brought up for editing and vice versa?
 
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… is quite comprehensive on the whole 'this' situation.
 
uggggh according to caniuse not really :(
 
that's where i doubt my coworker's logic there
 
6:22 PM
@PeeHaa there are polyfills. one is on that page i jsut pasted.
 
@PeeHaa bind is trivial to polyfill
 
he wants both editable at the same time
 
awesome
Ah yes. Thanks @Luggage, @ssube!
 
Hi i'm making a ajax call but it waiting for a audio media that starts playing to load how can i make request parallel to the audio media
 
@maniteja Welcome to the JavaScript chat! Please review the room pseudo-rules. Please don't ask if you can ask or if anyone's around; just ask your question, and if anyone's free and interested they'll help.
 
6:32 PM
i'm making a ajax call but it waiting for a audio media that starts playing to load how can i make request parallel to the audio media loading
 
@ApathyBear You don't need the else
 
@ApathyBear you got some == in there with your ===. Why string slice and not substr? n|0 fails if n > 2^32-1
for appearances, I would prefer a single return from that method, just assign the value to a variable and return that at the very end
 
Hi all
 
@PeeHaa good point.
@ssube I am still fuzzy on the different times to use == vs ===. Never heard of substr, but thanks for that.
 
6:39 PM
@ApathyBear Always use ===. There no fuzziness anymore ;-)
 
@ssube Also how would you check for an integer then?
 
@ApathyBear a really dumb way is n.toString().indexOf('.') === -1
 
=== is a strict comparison. == will 'coerce types' if it'll make things be equal. e.g. the string "2" == 2 but does NOT === 2
 
n % 1 === 0
 
4294968999.56 | 0
 
6:40 PM
@ssube 1703
 
obvs not right
 
@ssube false
 
!!> 4294968999.56.toString().indexOf('.') === -1
damn edit button
anyway, the latter works better, but can still fail on really large numbers
!!> 18446744073709551616.9283759.toString()
 
@ssube "18446744073709552000"
 
why not just use parseInt and check equality?
 
6:43 PM
!!> var n = 18446744073709551616.9283759; parseInt(n, 10) === n;
 
@ssube true
 
damn ieee
 
@ApathyBear Told ya.
 
@SomeKittens lmfao
@ssube "I prefer single return with a variable to hold the value, especially when you have 3+ branches (you have 5 return statements here)."
Not realy sure what you are saying here, can you explain a little more? Branches?
 
@ssube edit button? Don't you just use the arrow keys to edit recent comments?
 
6:46 PM
@Shmiddty yeah, that's what always screws me up
 
@ssube well, since no other ways work on that large number either... :P
 
@ApathyBear so, you have if (x) { return y; } else if (y) { return z; } else { return w; }. Because every branch returns, you can do var r = null; if (x) { r = y; } else if (y) { r = z; } else { r = w; } return r;
The advantage is that your function now has a single entrance and exit.
It may branch in the middle, but will always start and return at the same spot. Somewhat easier to comprehend, much easier to test.
IMO
 
Oh I see what you are saying, thanks for the tip @ssube
 
almost done this version from requirejs to webpack.. i think it might actually work out
 
I just downvoted Raynos for the first time
 
6:48 PM
0
Q: Ajax call waiting for audio media load

manitejaHi I have a web page where I'm loading data through an Ajax call and in the page i have a HTML5 <audio> element. When the user click on the a link the content is load with out any delay. But when a user is trying to play the <audio> element and then click on the content the Ajax call is waiting f...

 
@ssube But that would mean you would have to read the entire thing instead of just the return
 
@ssube but that is 1 extra variable! :p
 
Yeah, that's a great general-purpose CS motto: minimize execution paths! It really makes debugging easier, and often results in fewer bugs up front
 
also, for consistency with default return values of functions, I would initialize r with undefined (or just declare it)
 
6:50 PM
@PeeHaa but it decreases the chance of forgetting a return in one of the branches
@AwalGarg not a bad idea. If you have a default value, initializing to that works well.
 
:)
 
@ssube but I would have to read it more often. finding out I missed a return happens only once
 
@PeeHaa or once per branch. This way, you know that the function will always exit in the same spot.
 
@BenjaminGruenbaum It misses the point of maps vs. weak maps
 
@Zirak oh really? I didn't notice :D
 
6:52 PM
@ssube I still have to read the entire thing
 
I gave him a month to fix it too
 
You're getting old, then
 
Should've just raged
 
I just remembered it today since I answered a weakmap question so I figured I'd go back and check if he fixed it
 
6:54 PM
@Zirak @BenjaminGruenbaum ^ (special pings for dev tool wizards)
 
baaaaa, baaaa
Watch me bleat
@AwalGarg does Chrome do this correctly?
@Zirak I think I'll just dupe-close it as a duplicate of the new one
 
Nope. It is not implemented in either browsers.
 
Open an issue for the chrome dev tools too, it's a good idea
 
where?
(also, votes (if you really like it) are appreciated ofcourse)
 

« first day (1629 days earlier)      last day (3318 days later) »