Posts

Showing posts with the label javascript

How to set initial custom variable date upon datepicker opening in Materialize

7 0 I use two Materialize datepickers. Upon opening the date picker I want the date that in already in html input field to be displayed / used by the date picker. I was thinkig of onOpen callback and there use native .setDate() function. But I got two date pickers and did not find if onOpen accepts any arguments. var datepickerOptions ={ format: 'yyyy-mm-dd', autoClose : "true", firstDay : 1, onOpen : function(arg) { console.log(arg) } } document.addEventListener('DOMContentLoaded', function() { var elems = document.querySelectorAll('.datepicker'); var instances = M.Datepicker.init(elems, datepickerOptions); }); I am using Materialize v1.0. and working jsFiddle is here ...

403 Response code - Request Blocked when using Cowin setu APIs

6 1 I was just trying to make covid vaccine alert using Cowin Setu API (India) in nodejs. But I am facing some strange thing, whenever I hit get request I got 403 response code from cloudfront says 'Request Blocked' but the same is working from postman as well as from browser. Please help me in this Getting this error:- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <TITLE>ERROR: The request could not be satisfied</TITLE> </HEAD><BODY> <H1>403 ERROR</H1> <H2>The request could not be satisfied.</H2> <HR no...

Bootstrap v5 modal show issue

2 2 I decided to go ahead and update my site to the latest version of Bootstrap, version 5.0 and am having difficulty getting modals to work. Reading the migration guide said nothing about breaking modals and my site worked perfectly before. My code uses javascript/jQuery to fire off the modal after the ajax loads the text. The ajax part still works fine, but it's not firing the modal after it retrieves it. I'm using the latest bootstrap.bundle.min.js. $( document ).ready(function() { $('.hourModal').click(function(){ var obj_id = $(this).data('id'); $.ajax({ url: 'ajax-multi.php', type: 'POST', data: {obj_id: obj_id,role:'some_role'}, //dataType: 'html', success...

Update state within listener that is inside useEffect

7 2 I have a hook called useQueryEvents that 1) fetches all past transactions for a user and 2) listens to the network for incoming/outgoing transactions. In both cases the transactions are passed into a function addActionToActivity that simply appends it to the activity array and updates it in the context state under the key activity . I can't get the activity to sync correctly. Whenever the state updates it does not have the last transaction because it's always one step behind. If I add activity to the dependancy it works but then starts a new listener (due to the whole function being called again with the new activity value) which causes an infinity-like-loop which keeps switching up the state. function useQueryEvents() { const { state: { connectedNet...

Pointfree dynamic function composition

4 I'm trying to refactor this function to be pointfree. function siblings(me) { return R.pipe(family, R.reject(equalsMe(me)))(me); } I'd like to pass me to a function down the pipe along with the value that family returns. Tried a few things with R.useWith or R.converge with R.identity or R.__ (not even sure if I should be using that) but found nothing to work. javascript functional-programming ramda.js pointfree Share Improve this question Fol...

JS - Why array.sort() doesn't return the same result for objects and numbers?

5 Sorting an array of objects (by a property of type number) doesn't return a sorted result like for an array of numbers. Why so ? How to make it sort like for numbers ? Demo: Sorting an array of numbers const sorted = [0, 5, 2, undefined, 3, 1, 4] .sort((a, b) => a - b); console.log(sorted); Demo: Sorting an array of objects const notSorted = [ {i:0}, {i:5}, {i:2}, {i: undefined}, {i:3}, {i:1}, {i:4}, ] .sort((a, b) => a.i - b.i) .map(a => a.i); console.log(notSorted); I am currently on Chrome 90. Maybe some other browsers or engines don't have this issue. Tell me. javascript sorting ...

REST API Best practice ? return Empty object vs no object

5 The bounty expires in 16 hours . Answers to this question are eligible for a +50 reputation bounty. maaz is looking for an answer from a reputable source . let's say i have an API that returns users wallet balance and List of wallet transactions which is going to expiry response = { user_balance: 20 expiring_credits : [ {object 1 } {object 2} ] } in case if user dont have any expiring transactions we can format respose in 2 ways option 1 response = { user_balance: ...

Why doesn't triggering click() inside a click event listener cause an infinite loop?

50 8 Can someone explain the program flow of this JavaScript code: const $leaveRoom = document.querySelector('#leave-button'); let a = 1; $leaveRoom.addEventListener('click', () => { console.log(a); console.log("check"); a++; $leaveRoom.click(); console.log(a); a++; }); <button id="leave-button">Leave Room</button> The Output was: 1 check 2 check 3 4 This question may sound dumb but I am new to JavaScript. I am not able to understand the program flow of this code. I want to know how did I get 3 & 4 in the output. javascript html addeventlistener ...

Why does nuxt give me this error with vue-chartjs?

5 3 I get this error while trying to make vue-chartjs work WARN in ./node_modules/vue-chartjs/es/BaseCharts.js "export 'default' (imported as 'Chart') was not found in 'chart.js' And also this in devtools: TypeError: chart_js__WEBPACK_IMPORTED_MODULE_0__.default is not a constructor Steps to recreate: Create nuxt app with: $ yarn create nuxt-app <project_name> Add vue-chartjs with $ yarn add vue-chartjs chart.js Add following code which should work according to vue-chartjs docs ~/components/BarChart.js import { Bar } from 'vue-chartjs' export default { extends: Bar, props: ['data', 'options'], mounted() { this.renderChart(this.data, this.options) }, } ~/pages/index.vue <template...

Google Apps Script function executes when I run it manually, but fails when run as trigger, citing error code INTERNAL [closed]

4 2 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 22 days ago . Improve this question I have a Google Forms linked to ...