Skip to main content

Posts

Showing posts from 2022

OTP verification 2 minutes count down timer

Java Script  let timerOn = true; function timer(remaining) {   var m = Math.floor(remaining / 60);   var s = remaining % 60;   m = m < 10 ? '0' + m : m;   s = s < 10 ? '0' + s : s;   document.getElementById('timer').innerHTML = m + ':' + s;   remaining -= 1;   if(remaining >= 0 && timerOn) {     setTimeout(function() {         timer(remaining);     }, 1000);     return;   }   if(!timerOn) {     // Do validate stuff here     return;   }   // Do timeout stuff here   alert('Timeout for otp'); } // Then Call the function of Timer // timer(120); HTML <input type="text" name="otp" placeholer="Enter your otp"/> <div>Time left = <span id="timer"></span></div>

How to Get Current Date & Time in React

useEffect(() => { const dateString = Date.now()     const formatDate = (dateString) => {       const options = { year: "numeric", month: "long", day: "numeric"}       return new Date(dateString).toLocaleString(undefined, options)     }     alert(JSON.stringify(formatDate(dateString))) }, []) ------------------------------------------------------------------------------------------------------------------ If don't want to use options and just want to use dd/mm/yyyy format then use below code. const dateString = Date.now()     const formatDate = (dateString) => {       return new Date(dateString).toLocaleString('en-GB')     } alert(JSON.stringify(formatDate(dateString)))
 How can I validate I have drawn something in jSignature panel or not? if( $sigdiv.jSignature('getData', 'native').length == 0) {     alert('Please Enter Signature..');  } Note:   $sigdiv variable must be change as per your JSignature container variable
 How do you hide the warnings in React Native ? Update: React Native 0.63+ import { LogBox } from 'react-native'; LogBox.ignoreLogs(['Warning: ...']); // Ignore log notification by message LogBox.ignoreAllLogs();//Ignore all log notifications to ignore all log notifications
 Fire event only on image change Javascript $("#Imgphoto").on('change',function() {                 console.log('img uploaded'); }); HTML < input type = "file" id = "Imgphoto" >
 jQuery select change show/hide div event <script>   $(document).ready(function(){     $('#selectID').on('change', function() {       if ( this.value == 'red')       {         $("#divid").show();       }       else       {         $("#divid").hide();       }     }); }); </script>
Prevent SweetAlert to be closed on clicking outside the popup window If you are using Sweet Alert 2, you can use this configuration allowOutsideClick: false, To stop closing by escape key use below also: allowEscapeKey: false,
  Check if inputs are empty using jQuery Option 1 $( 'input' ). blur ( function ( ) { if ( !$( this ). val () ) { $( this ). parents ( 'p' ). addClass ( 'warning' ); } }); Option 2 $( input' ). blur ( function ( ) { if ( $( this ). val (). length === 0 ) { $( this ). parents ( 'p' ). addClass ( 'warning' ); } }); Option 3 $( input' ). blur ( function ( ) { if ( ! this . value ) { $( this ). parents ( 'p' ). addClass ( 'warning' ); } });