Posts by Sergio • 133,294 points
2,786 posts
-
4
votes1
answer57
viewsA: Alert being repeated through . each() ajax
You should consider only sending 1 ajax to the server and letting the server make the changes to the database. If that application is large and you have many users sending N ajax that way it can be…
-
1
votes1
answer615
viewsA: Use AJAX return in other functions
Global variables should be avoided as mentioned. Because they can collide with other global names, and because they can be manipulated by someone else’s code. But often we need variables accessible…
-
0
votes1
answer870
viewsA: Taking multiple equal input values and storing in an array with Javascript/jQuery
Creates a selector that picks up all <div class='pergunta'> and then do a mapping to get the values of the title and type. An example would be like this: const arr =…
-
1
votes3
answers632
viewsA: Filter array of dates
You have to convert those strings into numerical values or dates in order to work them. Two suggestions: Converting in seconds function hhmmToMin(str) { const [h, m] = str.split(':').map(Number);…
javascriptanswered Sergio 133,294 -
4
votes3
answers1372
viewsA: Transforming String into an Array - Javascript
From what I see in this array [["0250A002ADST"],["T664420 - Amarelo"]... Each sub-array has only one string. So you need to map this array to remove each subarray and leave in place the string it…
-
1
votes1
answer257
viewsA: Change the json value
You can use the .map() to do this, an example would be: const arr = [{"id": 1, "preco": "R$50"}, {"id": 2, "preco": "R$70"}]; const formatado = arr.map(obj => { return { id: obj.id, preco:…
-
1
votes1
answer21
viewsA: Ordering prop based on another prop
There’s a Take on Github with exactly this doubt. What is suggested there by one of the members of the Vue team is to make this check within the created which is called before the component is…
-
2
votes1
answer349
viewsA: Replace com Vuejs
In this case it would be better to use the v-html. This tool can open safety holes in the application, so it should be used carefully. But for the purpose you intend to do so you can do so: <p…
-
1
votes1
answer64
viewsA: Dirty Checking Angularjs and Vuejs
From what I know of Angular o ng-model and the v-model are the same idea. A quick search confirmed this. There is much talk today of unidirectional data Binding, which means that the state/data…
-
1
votes1
answer419
viewsA: Pass $route as parameter to a Vue JS function
If the $store is a property of the component you can use so: <v-btn color="info" v-on:click="getProximo($route)"> Próximo </v-btn> Or else use v-on:click="getProximo" and then within the…
-
6
votes5
answers1186
viewsA: How to use the reduce (reduce) operation on objects?
In your first example you are not passing the initial value of the sum, you should do that, is the second argument of .reduce(fn, valorInicial). This part is the same in the two examples. The…
-
0
votes2
answers101
viewsA: How to use the $ jquery in wordpress?
wordpress does this for security, not to happen load other libraries that use the $ and that are not jQuery. If you’re sure that doesn’t happen, and the library you need to use really has the $…
-
1
votes1
answer80
viewsA: Make code that uses Promises work also on older browsers
You can do it with callbacks like this: function getNome(nome, cb) { const url = 'https://httpbin.org/get?nome=' + nome; var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.onload = function()…
-
3
votes1
answer55
viewsA: CSS transition ignored when the array order in v-for changes
The problem was that the .sort() was changing the position of the elements in the v-for and this made Vue think that these were new elements. Configuring the left position otherwise solves the…
-
10
votes1
answer1726
viewsA: What is reactivity in Javascript?
The way you used it is not reactive, it is kind of pooling, go looking for changes and this does not scale, ie it is very heavy to be re-read and compare values in small time intervals. The concept…
-
1
votes3
answers1610
viewsA: Concatenate single quotes into date variable?
You can send with the JSON.stringify, that creates a quote string inside the string: var date = new Date(); var string = JSON.stringify(date); console.log(typeof string, string); // string…
-
2
votes1
answer339
viewsA: Unit test of a javascript fetch function with jest or mocha
The it takes two arguments. The description and function to run the test. This function can pass an argument, which is a function to run when the test is over. It would look like this: const…
-
3
votes1
answer191
viewsA: Wait for the variable to be completed
Yes, Promises in this case is useful. You can do this using Promise.all that waits for Promise to retrieve the data: function getNome(nome) { const url = 'https://httpbin.org/get?nome=' + nome;…
javascriptanswered Sergio 133,294 -
1
votes1
answer296
viewsA: Calling class method within a prefix returns: Uncaught (in Promise) Typeerror: _this3.updateShelvesState is not a Function
You must bind to the class you are in, so the method runs in the right context/this. Mute onChangeShelf={this.onChangeShelf} for onChangeShelf={this.onChangeShelf.bind(this)}…
-
1
votes1
answer365
viewsA: JSON created with PHP pass to JAVASCRIPT
You have extra quotes and you should use ; in PHP. Then you have to parse that string for a JSON. You can do this in Javascript with JSON.parse Mute: var arrayOfObjects = "<?="$reader"?>"; for…
-
6
votes2
answers305
viewsA: Button conflict when sending form with jquery
You have to use type="button" if not the browser thinks it is a commit button. Mute <button>outro botão</button> for <button type="button>outro botão</button> On MDN you can…
-
5
votes1
answer39
viewsA: Calculo via Javascript
These values are in the format String and not Number. And how Javascript uses + also to join/concatenate strings he ends up thinking that this is text. To turn number text into numbers that…
javascriptanswered Sergio 133,294 -
5
votes3
answers307
viewsA: Button and span logic from CSS
You can do this with the adjacent element selector +. To do this only with CSS you have to use !important for the purpose of display: none; inline in the element being undone. It would look like…
-
4
votes1
answer92
viewsA: Disable javascript unchecked checkbox
You can do it like this: $('input[type=checkbox]').each(function() { if (!this.checked) this.disabled = true; }); <script…
javascriptanswered Sergio 133,294 -
5
votes4
answers10811
viewsA: How to get the text of the selected option inside a select?
You can use select.children[select.selectedIndex] and then textContent: Example: var select = document.querySelector('select'); var option = select.children[select.selectedIndex]; var texto =…
javascriptanswered Sergio 133,294 -
4
votes2
answers124
viewsA: Time on stopwatch
You can do it with the same minute logic relative to seconds. A hint (with some code changes): // Tempo em segundos var credito = 7200; var countdownTimer; function stopTimer() {…
javascriptanswered Sergio 133,294 -
0
votes1
answer4588
viewsA: How to take something from an input text and pass by reference?
You can do this in different ways. One of them is keeping the input value by listening to events input, and there the value is already in the state waiting to be used: const Chat = () => null;…
-
1
votes1
answer1133
viewsA: IF-Else Reactjs Json condition
It is not allowed in JSX syntax to have conditions in the middle of HTML. You must have {} and the condition inside. It would look like this: const mensagens = this.state.data.map(obj => { return…
-
1
votes1
answer105
viewsA: Close <li> by clicking on the next
You can go through all the ".visualizar_mensagem" and check if the ID is the same as the clicked one. It would be better if you gave a class to what is open, so the close selector could be more…
-
2
votes1
answer1640
viewsA: Picking up parts of a JSON vector
You can do it like this, using the this.state.data as array that is and iterating with map to generate JSX class App extends React.Component { constructor(props) { super(props); this.state = { data:…
-
2
votes2
answers824
viewsA: Disabled HTML and Jquery property
You have to wear a String for the name of the property. Mute .prop(disabled, false); for .prop('disabled', false); $(document).ready(function() { $("#b2").click(function() {…
-
1
votes1
answer23
viewsA: Append data-slb-group="slb"
Once the images are inside <a> you can use the selector a[data-slb-active] and then .appendTo('.images'); thus: $('a[data-slb-active]').appendTo('.images'); <script…
-
1
votes1
answer146
viewsA: Display Array Data in Jquery table
You have a lot of code problems: situation is set twice. One as a function, another as an array Usa Number() around the numbers, to convert them from text to number after if (validar) { should have…
-
1
votes1
answer626
viewsA: How to pass a JSON object to another function?
This happens because the json will be received asynchronously. The concept to take into account in React is that everything is zeroed at the beginning. And then they arrive and change values,…
-
1
votes2
answers1155
viewsA: close div by clicking outside it
You can use the e.target to know which element is clicked and whether it is inside the element you are looking for. You can use the e.target.closest(seletor) that climbs the DOM until finding a…
-
4
votes2
answers434
viewsA: Javascript - React JS
You have to use the setState, This is what the React API calls render again. An example would be like this: constructor(props) { super(props); this.state = { data: {} } } componentDidMount(){ let…
-
0
votes2
answers179
viewsA: Jquery taking the <i> parent
Since you are mounting this in PHP you have 2 possibilities: Passing ID with PHP with onclick="delete("{{ $client->id }}")": <tbody> @foreach($clients as $client) <tr class="editLink"…
-
1
votes1
answer245
viewsA: problem reading external NODEJS Json
Treat that answer as a stream and creates a function that processes the pieces that arrive until the text is complete. It could be something like this, that I tested here: const https =…
-
3
votes2
answers209
viewsA: Get first value before comma
You don’t need jQuery for this, with Javascript it is simple and you can do so, assuming that the date format is always the same: var span = document.getElementById("organizerContainer-date"); var…
-
5
votes1
answer2123
viewsA: Decimals without rounding in javascript
I did something similar here at Sopt but I can’t find... :( Here is another suggestion. Multiply the numbers you want by the order of magnitude equal to the number of decimals. Then you take the…
javascriptanswered Sergio 133,294 -
3
votes2
answers1323
viewsA: Get CSS by Javascript
You can use the window.getComputedStyle(el), this will give something similar to an object where you can read its properties to know which styles are applied. He’s pretty big, 'cause he mentions all…
-
2
votes1
answer58
viewsA: Sort an array within an object, entering all hierarchies of it
Since the .sort() changes the array directly you can do so: // ordenar primeiro os sub menus data.layout.menu_events.forEach( event => event.sub_menu_items &&…
-
4
votes2
answers917
viewsA: Take the last word of a string and put it at the beginning with jQuery
Three suggestions: var frase = 'Amanhã vai chover'; // maneira mais moderna A var palavras = frase.split(' '); var reordenado1 = `${palavras.pop()}, ${[...palavras].join(' ')}`;…
-
3
votes1
answer45
viewsA: How to use a function of an object as an argument of another function
When you pass the callback to window.requestAnimationFrame the function loop will be run again. It will run with the right context because you use .bind(this) but without arguments. The objectLoop…
-
2
votes1
answer790
viewsA: Compare 2 arrays and create a new array if they have the same Id
You can copy each object into the array to avoid changing data outside of this mapping, and then map the property atividades one to one searching in array2 by the corresponding object using the…
-
5
votes2
answers109
viewsA: Warn when time is different from time
If your input is minutos:segundos:milisegundos you may know if the difference between the two is less than 300ms for example like: function diff300(a, b) { a = a.split(':').map(Number); b =…
javascriptanswered Sergio 133,294 -
1
votes5
answers2427
viewsA: Get clicked element position
You can use the .closest('tr') to get the tr and then the .indexOf(. For example: function removeLinha(element) { const trash = element.closest('tr'); const index =…
-
4
votes3
answers269
viewsA: What would this Jquery code look like in pure JS?
As you rightly pointed out, native Javascript has the toggle which can help here. A version of this code in modern Javascript could be like this: window.onload = function() { var navs =…
-
0
votes1
answer129
views -
3
votes1
answer398
viewsA: Input[number] accept numbers only in Firefox
You can force this with an event headphone from keydown which detects whether the character entered is a digit by comparing the key code. An example would be: var input =…