npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ra-remote-validator

v1.0.8

Published

React-Admin (3.*) remote validator

Downloads

8

Readme

ra-remote-validator

React-Admin (3.*) remote validator

NPM JavaScript Style Guide

Install

npm install --save ra-remote-validator

Usage

Edit your admin access point:

import React, { Component } from "react";
import { errorsReducer, errorsSaga } from "ra-remote-validator";
const App = () => (
  <Admin
    customReducers={{
      errors: errorsReducer
    }}
    customSagas={[errorsSaga]}
  >
    <Resource />
  </Admin>
);

After you can customize your Create/Edit views adding few settings:

import { compose } from "recompose";
import RemoteErrorsInterceptor, { withErrors } from "ra-remote-validator";

const MyCustomFormCreate = ({ dispatch, validate, errors, ...props }) => (
  <Create {...props}>
    <SimpleForm redirect="list" validate={validate}>
      <RemoteErrorsInterceptor errors={errors} dispatch={dispatch} />
      <TextInput source="code" />
      <TextInput source="name" />
    </SimpleForm>
  </Create>
);

export default compose(withErrors)(MyCustomFormCreate);

The validate method is valorized with lambda that simply returns errors provided by props. Inside the form, to ensure benefits provided by react-final-form, we have to add a simple component (that returns null anyway) called RemoteErrorsInterceptor, this component will be responsible for the error's state management inside every field of the form.

Finally the entire component is exported using withErrors that will provide access to many props: errors, validate, dispatch.

API

My primary goals was to implement a library compatible with CakePHP validation errors schema. But if you want to implements your own schema, you can use setErrorsMapper function. With this function you can parse server response and returns validation details like in this example:

import { setErrorsMapper } from "ra-remote-validator";

setErrorsMapper(action => {
  const { payload } = action;
  // TODO: payload contains your server response.
  return {
    // Validation errors like you do with client side validation.
    // But now you can use your server validation data.
  };
});

Notes: setErrorsMapper can be called everywhere in your app, this function will replace default validation function and I suggest you to exec the configuration inside your app index.js (in the starting point).

Please: I've implemented this library after checking the capabilities of react-final-form. I will really appreciate if someone has new suggestion that can be used to improve this project in terms of code or design. In any case I hope this can help you too.

License

MIT © RoBYCoNTe