validator_base_name_unique (zotonic_mod_base v1.0.0-rc.17)

A validator to check whether a resource’s name is unique:

<input type="text" id="name" name="name" value="" />
{% validate id="name" type={name_unique} %}

Optionally, pass an id parameter to exclude that particular id when testing for uniqueness. This is useful when you want to exclude the name of the resource currently being edited:

<input type="text" id="name" name="name" value="" />
{% validate id="name" type={name_unique id=id} %}

You can also pass a failure_message:

<input type="text" id="name" name="name" value="" />
{% validate id="name" type={name_unique id=id failure_message=_"Eek! Already used!"} %}

See also

Forms and validation, username_unique, page_path_unique

Summary

Functions

event/2

-spec event(#postback{message :: term(),
                      trigger :: binary() | undefined,
                      target :: binary() | undefined},
            z:context()) ->
               z:context().

render_validator/5

validate/5

-spec validate(name_unique, binary(), term(), list(), z:context()) ->
                  {{ok, binary()}, z:context()} |
                  {{error, m_rsc:resource(), atom() | binary()},
                   #context{cowreq :: cowboy_req:req() | undefined,
                            cowenv :: cowboy_middleware:env() | undefined,
                            site :: atom(),
                            controller_module :: atom() | undefined,
                            client_id :: binary() | undefined,
                            client_topic :: mqtt_sessions:topic() | undefined,
                            routing_id :: binary() | undefined,
                            acl :: term() | admin | undefined,
                            acl_is_read_only :: boolean(),
                            user_id :: integer() | authenticated | undefined,
                            render_state :: undefined | z_render:render_state(),
                            db :: {atom(), atom()} | undefined,
                            dbc :: pid() | undefined,
                            language :: [atom()],
                            tz :: binary(),
                            props :: map(),
                            depcache :: pid() | atom(),
                            dispatcher :: pid() | atom(),
                            template_server :: pid() | atom(),
                            scomp_server :: pid() | atom(),
                            dropbox_server :: pid() | atom(),
                            pivot_server :: pid() | atom(),
                            module_indexer :: pid() | atom(),
                            translation_table :: atom()}}.