Posts

Showing posts with the label javascript

Disable switch button in React

Image
Disable switch button in React If I click on the Annual radio button, then switch button (labelled "half day") should be hidden or disabled (only for Annual radio button). How do I do this in React? <RadioGroup onChange={this.onChange} value={this.state.leavevalue}> <Radio value={1}>Casual</Radio> <Radio value={2}>Medical</Radio> <Radio value={3}>Annual</Radio> <Radio value={4}>Lieu</Radio> <Radio value={5}>Special</Radio> <Radio value={6}>Maternity</Radio> <Radio value={7}>Paternity</Radio> <Radio value={8}>NoPay</Radio> </RadioGroup> This is my switch button code : <Switch onChange={this.handleHalfDay} checked={this.state.isHalfDay} /> This is my onChange function: onChange = (e) => { this.setState({ leavevalue: e.target.value, isHalfDay: false, }); } My radio buttons and the switch button: ...

Can't get store value after the value was updated using React

Can't get store value after the value was updated using React I have a SearchBar component and it has a subcomponent SearchBarItem. I passed the method handleSelectItem() to subcomponent to dispatch value to store and it works (I saw it from the Redux tool in Chrome). handleSelectItem() Then, when I tried to get the value from the method submitSearch() , which I also passed it from the parent component, it shows: submitSearch() Cannot read property 'area' of undefined. I'm still not so familiar with React. If someone can help, it will be very appreciated. Thanks in advance. This is parent component SearchBar: class SearchBar extends Component { handleSelectItem = (selectCategory, selectedItem) => { if (selectCategory === 'areas') { this.props.searchActions.setSearchArea(selectedItem); } } submitSearch() { console.log(this.props.area); // this one is undefined } render() { return ( <div className="searchBar...

How to Rename images while uploading in add / remove dynamic fields

How to Rename images while uploading in add / remove dynamic fields I am creating a project in which I have created several Dynamic Add/Remove fields. Every thing is working perfectly and have no issues. I have created add/remove image file fields. When I upload images it gets uploaded perfectly. But I want these images to get rename using rand() function. rand() <?php if ( isset( $_POST['project_draft'] ) ) { $member_details->member_image = array_map( 'sanitize_file_name', $_FILES['member_image']['name'] ); $member_details->member_name = array_map( 'sanitize_text_field', $_POST['member_name'] ); $member_details->member_role = array_map( 'sanitize_text_field', $_POST['member_role'] ); $member_details->member_email = array_map( 'sanitize_text_field', $_POST['member_email'] ); $member_details->member_facebook_id = array_map( 'sanitize_text_field', $_POST['member_facebook_id'...

API Fetch failed with No 'Access-Control-Allow-Origin' header is present on the requested resource

API Fetch failed with No 'Access-Control-Allow-Origin' header is present on the requested resource I've been running out of my mind trying to deal with this problem. I'm running React.js on my local machine under http://localhost:3000 and i'm trying to use the fetch method to load some data from http://api.population.io:80/1.0/countries http://api.population.io:80/1.0/countries According to the API owner "The standard response format is JSON (application/json) with CORS for cross-domain requests." I've tried various combinations of headers and what i have right now is this setup: fetch("http://api.population.io:80/1.0/countries",{ method: 'GET', mode: 'cors', headers: new Headers({ "Content-Type": "application/json", 'Access-Control-Allow-Origin':'*' }) }) According to Chrome, the following headers are being sent through the request: Access-Control-Request-Hea...

select picture by choosing date in datepicker

select picture by choosing date in datepicker I would like to create a simple web page, where user can select a picture by choosing date in datepicker. The picture filenames consist date string. For example: img-2018-06-24.png. So far, I could get work this datepicker example: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI Datepicker - Default functionality</title> <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="http://code.jquery.com/jquery-1.10.2.js"></script> <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <link rel="stylesheet" href="/resources/demos/style.css"> <script> $(function() { $( "#datepicker" ).datepicker(); //selecting the button and adding a click event $("#alert").click(function()...

How to Loop through Values in Google Sheet while creating a Trigger?

How to Loop through Values in Google Sheet while creating a Trigger? I have Google Apps Script Code in the following format: var key = "ID of the Sheet"; var key1 = "ID of the Sheet"; function createTriggers() { ScriptApp.newTrigger('filter') .forSpreadsheet(key) .onEdit() .create(); } function createTriggers() { ScriptApp.newTrigger('filter') .forSpreadsheet(key1) .onEdit() .create(); } How to loop through all keys (key, key1, key2...) and create triggers via a single function? Pretty broad question. Can you be more specific? What are you trying to accomplish? – Cooper 3 mins ago I want to create a trigger for multiple sheets in a standalone script, as of now, I have to create a separate function for each trigger as seen in the above exa...

How to return redux state to initial state?

How to return redux state to initial state? I'm having surprisingly difficult time figuring this out, essentially I'm trying to set state to initial state, so far I tried: // -- Initial state ------------------------------------------------------------ const INITIAL_STATE = { search: { listings: }, listings: } // -- Story structure for story editor ----------------------------------------- export default function(state = INITIAL_STATE, action) { switch(action.type) { case ACTIONS.RESET_STATE: return { ...state, INITIAL_STATE } default: return state; } } this just adds initial state to existing one case ACTIONS.RESET_STATE: return { ...state, state = INITIAL_STATE } this returns error case ACTIONS.RESET_STATE: return { ...state, state: INITIAL_STATE } this is adding initial state to existing one gain case ACTIONS.RESET_STATE: return { ...state, search: { listings: }, listings: } This works, but I start getting weird mutation e...

Telerik MVC controls, OnDocumentReady is firing twice

Telerik MVC controls, OnDocumentReady is firing twice I'm new to Telerik MVC controls, so this may be something simple. I started out with making a new TelerikMvcApplication solution. Site.Master: </div> <%: Html.Telerik().ScriptRegistrar().DefaultGroup(group => group.Combined(true).Compress(true).Add("Index.js")) %> </body> </html> Index.aspx: <%: Html.Telerik().ScriptRegistrar().OnDocumentReady("Index.Init()") %> </asp:Content> Index.js: var Index = function () { return { Init: function () { alert('1'); } }; } (); When I load Index.aspx, the Init() function in Index.js is fired twice, so I see 2 alerts one after another. If I assign a click handler to a button inside the Init() function and hit the button with FireBug, it is actually showing 2 events being assigned to the button. Why is this happening? After some more firebugging, I figured out that both ...

Centered owl-carousel where each image has the same hight and keeps its aspect ratio

Centered owl-carousel where each image has the same hight and keeps its aspect ratio Is there an approach to to create a centered owl-carousel where each image has the same height without losing its aspect ratio? owl-carousel I tried to calculate the image sizes with JS/jQuery but then the calculation of the owl-carousel gets messed up. Same result with CSS s. example (jsfiddle): JS/jQuery owl-carousel CSS $(document).ready(function () { $('.loop').owlCarousel({ center: true, items: 3, loop: true, margin: 20 }); }); .owl-carousel .owl-stage { height: 150px; } .owl-carousel .owl-item { height: 100%; } .owl-carousel .owl-item .item { height: 100%; } .owl-carousel .owl-item img { height: 100% !important; width: auto !important; margin: 0 auto; } <link rel="stylesheet" type="text/css" href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.carousel.min.css"> <...

componentDidMount not being called after goBack navigation call

componentDidMount not being called after goBack navigation call I've set up a StackNavigator which will fire a redux action to fetch data on componentDidMount , after navigating to another screen and going back to the previous screen, componentDidMount is no longer firing and I'm presented with a white screen. I've tried to reset the StackNavigator using StackActions.reset but that just leads to my other screens not mounting as well and in turn presenting an empty screen. Is there a way to force componentDidMount after this.props.navigation.goBack() ? componentDidMount componentDidMount StackActions.reset componentDidMount this.props.navigation.goBack() Go Back Function _goBack = () => { this.props.navigation.goBack(); }; Navigation function to new screen _showQuest = (questId, questTitle ) => { this.props.navigation.navigate("Quest", { questId, questTitle, }); }; How are you rendering your components? It might be...

how to render a javascript files after a view is render in Angular

how to render a javascript files after a view is render in Angular I am new to angular and this is first time working with angular.js . I am trying to build an single page application in angular which has the following pages All my pages have jquery script to handle modal popup form submission etc. All of them work, but when i render those pages with ng-view inside index.html. Those script doesn't work,. They do not render as well. ng-view Can anyone please tell me how can i fix this issue or if there is any other way of doing the same keeping those jquery functions. Here is my file structure Index.html <html> ...... <header> <script src="<ANGULAR.JS>"></script> <script src="<ANGULAR ROUTE.JS"></script> <script src="<JQUERY>"></script> <script defer src="<OTHER SCRIPTS>"></script> </header> <body> <ng-view></ng-view> </bo...

Javascript - TypeError: x is not a function at done

Javascript - TypeError: x is not a function at done I am building my own browserside javascript sdk, using webpack and node. I have built a async/await document function, which simply submits a document to an api. This function could be called twice in the browser (if there is a second image) However on the second document function call i get the following error. TypeError: hsp.document is not a function at done index.html <script> hsp = new HSP(); // function called on button click async function done() { try { const doc = await hsp.document(transaction, token, url, this.frontBase64); console.log(doc); // If second image, submit it also. if(this.backBase64) { const doc = await hsp.document(transaction, token, url, this.backBase64); } } catch (er) { console.log(er); } } </script> sdk.js async document(transaction, token, url, doc) { try { this.document = await this.api.submit...

For loops in JavaScript functions

For loops in JavaScript functions const animals = ["dog", "cat", "tree frog"]; function pluralize(array) { for (var i = 0; i <= array.length; i++) { array[i] += "s" return (array) } } console.log(pluralize(animals)); My goal is to create a function that adds the s to the end of words. However when I ran my code s was only added to the first word in the array. Why was the s not added to the other words in the array? Because you immediately return in your loop. Move the return out of the loop to the end of the function. – ASDFGerte Jul 1 at 9:13 return return Also you should iterate to i < array.length . Otherwise you will operate on array[array.length] , which is after the last element. – ASDFGerte Jul 1 at 9:20 ...

Replace http links with anchor tag

Replace http links with anchor tag So i'm building a chat-client where i read the incoming-messages through json. However, I would like to be able to convert URLs to clickable anchor-tags instead. I've looked around but haven't really found any posts asking or getting an answer about this. This is my current code: if (json.type === 'message') { var val; var str = json.data.text; //message-string var here = str.match("([^s]+)"); // match any word until space <---| merge if (!here.search(/^http[s]?:///)){ //if it contains http / https <---| these? val = '<a href="' + here + ""> [Link] </a>"; } addMessage(json.data.author, val, json.data.color, new Date(json.data.time)); } else { console.log('Hmm..., I've never seen JSON like this:', json); } Thanks 1 Answer 1 You're never usin...

(check if) Mouse in cycle? (coordinate Js canvas)

(check if) Mouse in cycle? (coordinate Js canvas) So, I want to check, if the mouse is (clicked) inside of a ring. Here it (the ring) is : <canvas id="textur" width="1584" height="750"></canvas> <script> var textur = document.getElementById('textur'); var canvas = textur.getContext('2d');//Dimension zähler = 0; diff = ((1)*Math.PI*2*10).toFixed(2) canvas.lineWidth = 95 ; canvas.fillStyle = '#09F' canvas.strokeStyle = '#09F' canvas.textAlign = 'center' canvas.beginPath(); canvas.arc(150, 100, 5, 4.72, diff / 10 + 4.72, false) canvas.stroke(); </script> So, I know how to do it with a rectangle,but with a ring... I´m happy about every (useful) answer! Possible duplicate of Detect if user clicks inside a circle – AndroidNoobie Jul 1 at 9:08 ...

How to superimpose a canvas on an HTML5 video using object-fit cover?

How to superimpose a canvas on an HTML5 video using object-fit cover? I am refactoring this code: https://github.com/idevelop/predator-vision to superimpose heatmap on a video (with any resolution and aspect-ratio). I have the following html code: <div id="videos" class="embed-responsive"> <canvas id="heatmap" class="embed-responsive-item"></canvas> <video id="remote-video" autoplay muted playsinline class="embed-responsive-item"></video> </div> CSS: #remote-video { display: block; height: 100%; max-height: 100%; max-width: 100%; position: absolute; top: 0; left: 0; object-fit: cover; /* no letterboxing */ opacity: 1; -moz-transform: rotateY(180deg); -ms-transform: rotateY(180deg); -o-transform: rotateY(180deg); -webkit-transform: rotateY(180deg); transform: rotateY(180deg); transition: opacity 1s; width: 100%; } #re...