Skip to content

Instantly share code, notes, and snippets.

View logaretm's full-sized avatar
Validating your forms

Abdelrahman Awad logaretm

Validating your forms
View GitHub Profile
@logaretm
logaretm / isEventTargetComposable.ts
Last active April 10, 2024 14:46
Different ways to check if a keyDown or keyPress event is originating from a text element, usually to avoid processing it.
// There are multiple ways to check for that, here are a couple that I use!
export function isComposableElement(element: Maybe<HTMLElement | Element>) {
if (!element) {
return false;
}
return (
(element as HTMLElement).contentEditable === 'true' || element.tagName === 'INPUT' || element.tagName === 'TEXTAREA'
);
@logaretm
logaretm / sw.js
Created February 25, 2020 20:46
Caching GraphQL responses with Service Workers
const QUERY_CACHE_KEY = 'CACHE_V_0';
const GRAPHQL_URL = 'https://example.com/graphql';
self.addEventListener('fetch', e => {
if (isGraphql(e.request)) {
handleGraphQL(e);
}
});
const prepare = (req, res, next) => {
// not signed in, sees published things only.
if (!req.user) {
req.query.status = 'published';
}
// signed in and is admin, see whatever he wants.
if (req.user && req.user.isAdmin()) {
return next();
}
@logaretm
logaretm / Sluggable.php
Created January 2, 2017 06:53
Fills the slug column automatically for the models using this trait.
<?php
namespace App\Traits;
trait Sluggable
{
/**
* Boots the sluggable trait.
*/
public static function bootSluggable()

vee-validate 2.0.0-beta.15 Changelog:

  • All data-* attributes has been prefixed with vv to ensure no conflicts arise.
  • The validator now uses validate.js for the following rules: email, url, ip, numeric
  • New rules:
    • min_value: compares against a minimum numeric value.
    • max_value: compares against a maximum numeric value.
    • credit_card: validates a credit card number.
  • The validator now validtes on input and on blur by default.
  • You can specify the input events that trigger validation using data-vv-validate-on
@logaretm
logaretm / axiosPlugin.js
Last active October 23, 2018 09:55
Axios plugin to replace vue-resource
import axios from 'axios';
export default (Vue) => {
Object.defineProperties(Vue.prototype, {
$http: {
get() {
return axios;
}
}
});
@logaretm
logaretm / Settings.php
Created April 30, 2016 05:43
Class to manage user settiings in laravel.
<?php
namespace App;
class Settings
{
/**
* @var array
@logaretm
logaretm / directives.js
Last active May 3, 2017 11:43
VueJS Utility Directives: some useful VueJS directives.
// Cleans GET query parameters by disabling empty inputs using jquery.
Vue.directive('clean', {
onSubmit() {
$(':input', this).each(function() {
this.disabled = !($(this).val());
});
},
bind() {
$(this.el).submit(this.onSubmit);
@logaretm
logaretm / FilterIfPjax.php
Created October 14, 2015 10:58
The pjax middleware Jeffery Way explained on his Pjax Laracasts lesson
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Symfony\Component\DomCrawler\Crawler;
class FilterIfPjax