Posts by Luiz Felipe • 32,886 points
746 posts
-
0
votes1
answer43
viewsA: Difficulties in logical OR operator
TL;DR: You’re using the wrong operator. Your condition provides that if the URL field is empty or if the URL field is empty the code will be executed. This means that: If the file field is empty,…
-
1
votes2
answers43
viewsA: Change object class <i> within <a> tag
Just access the element son of the event target using the children and use the methods addClass and removeClass to exchange classes: $('.botao').on('click', function() {…
-
0
votes2
answers479
viewsA: Typescript build does not support Commonjs from Node.js
Although I didn’t feel like it was the most ideal, I managed to solve attributing value exported to keyword export: export = function alert(message: string) { console.log(message); } I think one…
-
4
votes2
answers63
viewsA: Make loop if condition hurt
Just use a repeat loop. The logic is simple: Before starting the loop, create a variable with the user’s initial response. As long as the answer is incorrect, do the question again until it is…
javascriptanswered Luiz Felipe 32,886 -
4
votes5
answers1315
viewsA: Join two events that have the same function
Cannot do what you want. The sample syntax you demonstrated in the question is invalid. What you can do is create a function that will encapsulate the entire block of code that you need to execute.…
-
4
votes1
answer147
viewsQ: Injection of dependencies into functions and not classes. Is it "wrong"?
It is not new that the concept of dependency injection is almost directly related to classes. Tell me "dependency injection" and I can imagine the following: // services/UserService.ts export…
-
3
votes1
answer537
viewsA: Function Ladder
The problem lies in the fact that, unlike other languages, to repeat a character in Javascript, you cannot do something like this: '#' * 5; // NaN Must use the method String.prototype.repeat.…
javascriptanswered Luiz Felipe 32,886 -
0
votes5
answers388
viewsA: How to exclude only a certain data from a React state
Just use the method filter to keep only properties that have an ID in the list different of the one you wish to exclude. For example: const state = [{ id: 1, nome: 'Julia', curso: 'Enfermagem', }, {…
-
1
votes1
answer1143
viewsA: Problem with module resolution
This happens because you are using pathcustom s, as evidenced in your Typescript configuration: "paths": { "@entities-services/*": ["src/modules/database/services/*"], "@entities/*":…
typescriptanswered Luiz Felipe 32,886 -
2
votes2
answers874
viewsA: How to pass an object inside a props?
In the component Musicas, you must define another key that does not props or do the spread of all object properties Music. I leave below two possible alternatives. Choose the one that seems simpler.…
-
3
votes2
answers79
viewsQ: Use user, email or one of the two for authentication?
I am developing an application that, like all others, will need the user’s email for some purposes. Each user will also have a unique username for their profile page: /u/:username The question is:…
-
0
votes2
answers461
viewsA: How to wait two promises before returning to function?
You must keep in mind that both _getImage how much _getVideo are functions that return Promises. Therefore, you must wait for your resolution from the function saveFiles. How do you want to expect…
-
11
votes3
answers5041
viewsA: How to make a project public to private on Github?
Just go to your repository settings by clicking "Settings": Then look for the section "Danger zone", at the end of the settings page: By clicking the button "Make private" (make it private), you may…
githubanswered Luiz Felipe 32,886 -
2
votes2
answers104
viewsA: Select all checkbox separated by groups
One of the simplest and most versatile ways to do this is to create a property data-* in the link to select all corresponding to the group. For example: <button…
-
1
votes3
answers597
viewsA: Summing up JSON values
You can use a simple repeat loop for: const data = { success: [ { cod: '158877', txt: '158877', fields: { Valor: '22,32', Resultado_Instância: 'Solicitação Encaminhada', Status: 'Em Andamento',…
-
1
votes1
answer20
viewsA: Handle object in Node via bank return
What happens is that you are changing the value of games after each iteration. Instead of alter all the array, you must add a new object after each iteration. Suppose the code below (what you…
-
0
votes1
answer115
viewsA: Problem Bringing Database Data to html
The problem is that you are trying to use a browser API on the server side. What you are trying to do in the row below is wrong. var e = document.getElementById('atendente').value; That’s why you’re…
-
0
votes2
answers821
viewsA: Are there possibilities to hide part of the html of the inspect?
Not. So far (and I imagine it always will be) is impossible conceal any resource forming part of front-end. This covers files and snippets of HTML, CSS, Javascript, and some others. What you can do…
-
5
votes3
answers113
viewsA: Call date by javascript
Inserting content into the DOM: To insert any text into the DOM, you can make use of techniques such as textContent, append, and others. Since we only want to insert a text with the current date…
-
0
votes1
answer134
viewsA: I cannot access SQL query property on Node.js
The problem is that your query is not returning a single object, but rather a list of objects. In your case, the return is exactly this: [ TextRow { cod_cli: 2, email_cli: 'Algum Valor', // Demais…
-
1
votes1
answer13
viewsA: Receiving Radio Box Nodelist and checking if this checked to apply logic
The simplest way to do this is to share the same attribute name of all the radios and use the event change to determine when another field is selected. Use name for this is even the most recommended…
javascriptanswered Luiz Felipe 32,886 -
0
votes3
answers209
viewsA: Undefined return when calling function
I will base my response on the assumption that you are using the library request in the code of your question. The problem is you’re trying to use await in a function that uses a callback, and does…
-
0
votes1
answer189
viewsA: Global Variable with Typescript
Simply put, you can access global variables like this: const globalVariable = (window as any).globalVariable For example: alert((window as any).globalVariable)…
-
2
votes2
answers107
viewsA: Use "Array.prototype.filter" to list what you do and what is not part of the condition
No. Javascript does not have this implementation natively, but nothing prevents you from doing a: function filter(array, cb) { if (typeof cb !== 'function') { throw new TypeError('Invalid `cb`…
-
2
votes2
answers157
viewsQ: Align element items according to class using flexbox
I have the following menu: body { padding: 1rem; } .menu { display: flex; padding: 0.5rem; border: solid 1px #000; } .item { border: solid 1px #444; padding: 0.25rem; } .item:not(:last-child) {…
-
6
votes2
answers479
viewsQ: Typescript build does not support Commonjs from Node.js
Let’s say I have a module alert.ts: export default function alert(message: string): void { console.log('Alerta: ' + message) } When performing the build using the tsc, and try to use the code…
-
2
votes1
answer235
viewsA: Did inverted string quote support appear in Ecmascript 6?
I wonder if that came up in that version. As you can find in the documentation on Template Strings on MDN, yes, this feature was added in the Ecmascript 6 specification.…
-
1
votes1
answer150
viewsA: Language change with JSON
The problem lies in this line of your Javascript code: var lang = $(this).attr('id'); To capture the value of a select at the event change jQuery, just use the $(this).val(). Therefore, the correct…
-
1
votes4
answers2052
viewsA: Is Ecmascript 6 supported by current browsers?
Yes, Ecmascript 6 is already being supported on browsers current. In this context, we have defined browsers as the latest versions of Chrome, Firefox, Safari, Edge, Opera, etc.. But before using a…
-
2
votes1
answer880
viewsA: Onchange event does not work in <select>
How is it possible to check on second line, you are accessing the property Value. The correct is value, since Javascript differs between upper and lower case letters. Also, you are looking for an…
-
1
votes1
answer322
viewsA: Take only one value in the query result to the database
You can use the AS to create an alias for COUNT(*), to make it easier to access in Javascript. So your query will look like this: SELECT COUNT(*) AS count FROM nome_da_tabela; The result will come…
-
3
votes2
answers67
viewsA: Is there a problem with using invented tags and attributes?
In HTML5, the use of "invented" tags is not recommended unless you are using technologies such as WebComponents. Learn more about them here. Regarding the HTML specification tags (such as…
-
2
votes1
answer1098
viewsA: If condition inside the map function
You cannot remove items directly by map, since, by definition, this method returns an array of the same length as the initial array, making only modifications to its values. In that case, you would…
javascriptanswered Luiz Felipe 32,886 -
2
votes2
answers914
viewsA: How does larger and smaller Javascript string checking work?
Javascript compares letter by letter, using the coding dictionary that JS uses (Unicode). Hence, strings are not compared on a whole, but are divided and each character is compared individually,…
-
1
votes1
answer41
viewsA: Redo array with maximum position limit
Just use the math, see: Suppose you have a list of 15 users and you have shown 3 of them. The rest of users can be obtained by subtracting 15 (the total length of the list) and 3 (the number of…
-
1
votes2
answers1240
viewsA: By clicking the button to call function Avascript the sume button
You are not updating the screen. This effect is given since you are using the document.write to write on screen. The functioning of document.write is simple: basically, while the page is loading, it…
-
3
votes8
answers34672
viewsA: Convert every first letter of every word into uppercase
Another alternative, based on the famous map: function titleize(string, separator = ' ') { return string .split(separator) .map((word) => word[0].toUpperCase() + word.slice(1).toLowerCase())…
javascriptanswered Luiz Felipe 32,886 -
2
votes2
answers339
viewsA: Dynamic select with Javascript
As the element <option> usually need a text to display and an attribute value, instead of a array, the most ideal would be for you to use an object: const options = { M: { 0: 'Selecione...',…
-
1
votes1
answer92
viewsA: Why do javascript events only work on the first element clicked?
This happens because you are using the method querySelector, which only selects the first element found in the DOM with the selector passed: const $lojas = document.querySelector(".lojas"); If you…
javascriptanswered Luiz Felipe 32,886 -
7
votes1
answer393
viewsA: await does not await execution of the President
TL;DR: The problem is not in asynchronous function and/or in await. As mentioned by @Leonardo Buta in the comments of the question, problem lies in its implementation of the examples getSenha and…
-
11
votes1
answer2366
viewsA: How to assign the result of a Promise to a variable?
TL;DR: If you want to follow good practices, you cannot assign the solved value of a Promise for a variable that is outside the callback of then or catch or asynchronous function. Read the following…
-
2
votes1
answer849
viewsA: How to create an object dynamically from an interface?
TL;DR: You can’t do this. Typescript is a superset Javascript. I imagine you already know this, so I won’t be long on this story that everyone already knows. The point is that Typescript code itself…
typescriptanswered Luiz Felipe 32,886 -
2
votes1
answer1140
viewsA: Convert date yyyy-mm-ddThh:mm:ss. z to dd/mm/yyyy with javascript
You can create a new instance of the class Date passing to string date to constructor and use the instance methods to create the formatted date. Note: To string passed as first argument for the…
javascriptanswered Luiz Felipe 32,886 -
2
votes2
answers67
viewsA: How to overwrite an image using text that is not clickable?
To prevent any kind of mouse interaction, you must use two CSS properties: user-select as none, that will prevent text selection; pointer-events as none, which will prevent any other mouse…
-
2
votes2
answers1995
viewsA: Remove mask with javascript
If values always come in these formats: R$ 12.000.000,00 R$ 12.000,00 R$ 12,00 You can create a function that does the following: Remove the R$ preceding all the values; Remove all points (.) (that…
javascriptanswered Luiz Felipe 32,886 -
1
votes2
answers97
viewsA: Accessing an element within the same element hierarchy
I think the simplest way to do that is to use the prev twice to reach the desired element. Then just use the children to access the rect and read the attribute data-id. const $el = $('.texto') //…
-
3
votes1
answer66
viewsA: Margin does not push content to the center
The class element side-menu-user-photo has a width (width) defined differently from site-menu-user-name, which does not have a width explicitly defined in your CSS, which makes it 100% wide. So…
cssanswered Luiz Felipe 32,886 -
2
votes2
answers65
viewsA: Why value looks different with printf and echo
The printf is a function that prints a formatted string in the console and returns the string length in numbers. For example: // Irá mostrar a string "Luiz Felipe" antes dos três hífens.…
phpanswered Luiz Felipe 32,886 -
1
votes1
answer105
viewsA: What would be the right and most complete way to start an html document?
The Boilerplate most basic will always contain a standard document using HTML5 and that has some tags meta, the title and the body: <!DOCTYPE html> <html lang="pt-BR"> <head>…
htmlanswered Luiz Felipe 32,886 -
3
votes1
answer133
viewsA: doubts about POST method
Yes, it’s vulnerable. You can see it through these two lines: $razaosocial = $_POST["razaosocial"]; $sql = mysqli_query($conexao, "INSERT INTO cliente VALUES ('', '".$razaosocial."') "); Imagine if…