I wanna use a custom validator with a more relevant message, the message with IS_NOT_IN_DB() reads* "Value already in database or empty", *how can i change the message to what i want it to be?
Mostw On Monday, May 20, 2019 at 9:36:32 AM UTC+2, Lovedie JC wrote: > > IS_NOT_IN_DB() > > On Mon, 20 May 2019, 10:07 mostwanted <godir...@gmail.com <javascript:>> > wrote: > >> I have a custom form that allows users to save information on what they >> are selling but the problem is that at times customers save similar items >> names and during a search by buyers the buyer gets a duplicate name >> results, what i want is to disable registering clients from saving the same >> item names, if the name they want to save is already in the database they >> should get a message that says, *"that name is already used, please >> choose a different name for your items" , *what would a custom validator >> that does this look like? Below is my APP code. >> >> *MODEL* >> db.define_table('black_market2', >> Field('regCode', requires=IS_NOT_EMPTY()), >> Field('fullNames', requires=IS_NOT_EMPTY()), >> Field('id_number', 'integer', requires=IS_NOT_EMPTY()), >> Field('contactNumber', requires=IS_NOT_EMPTY()), >> #Field('place', 'reference locations'), >> Field('geographical_place', requires=IS_NOT_EMPTY()), >> Field('located_at', requires=IS_NOT_EMPTY()), >> Field('product', requires=IS_NOT_EMPTY()), >> Field('model', requires=IS_NOT_EMPTY()), >> Field('productionYear', requires=IS_NOT_EMPTY()), >> Field('productSerialNumber', requires=IS_NOT_EMPTY()), >> Field('offerPrice', requires=IS_NOT_EMPTY()), >> format='%(product)s') >> >> >> >> *VIEW* >> <div id="itemDetails"> >> <input type="text" name="fullNames" class="field" id="fullName" >> placeholder="Full Names"/><br /> >> <div class="target" id="target"></div> >> >> <input type="text" name="id_number" class="field" id="id_number" >> placeholder="ID Number"/><br /> >> <div class="target" id="target"></div> >> >> <input type="text" name="contactNumber" class="field" id= >> "contactNumber" placeholder="Contact Number"/><br /> >> <div class="target" id="target"></div> >> >> <input type="text" name="geographical_place" class="field" id= >> "geographical_place" placeholder="Geographical Place"/><br /> >> <div class="target" id="target"></div> >> >> <input type="text" name="located_at" class="field" id="located_at" >> placeholder="Location"/><br /> >> <div class="target" id="target"></div> >> >> <input type="text" name="product" class="field" id="product" >> placeholder="What is your product?"/><br /> >> <div class="target" id="target"></div> >> >> <input type="text" name="model" class="field" id="model" placeholder="What >> is the Model?"/><br /> >> <div class="target" id="target"></div> >> >> <input type="text" name="productionYear" class="field" id= >> "productionYear" placeholder="Production Year?"/><br /> >> <div class="target" id="target"></div> >> >> <input type="text" name="productSerialNumber" class="field" id= >> "productSerialNumber" placeholder="Product Serial Number"/><br /> >> <div class="target" id="target"></div> >> >> <input type="text" name="offerPrice" class="field" class="field" id= >> "offerPrice" placeholder="Offer Price in Pulas"/><br /> >> <div class="target" id="target"></div> >> <hr /> >> <input type="submit" class="btn btn-default" value="Register"/> >> <input type="reset" class="btn btn-default" value="Cancel"/> >> </div> >> </div> >> <br /> >> >> >> >> </div> >> </form> >> >> <script> >> jQuery('#myform').submit(function() { >> ajax('{{=URL('blackMarket')}}', '[name=regCode], >> [name=fullNames],[name=id_number], >> [name=contactNumber],[name=geographical_place], [name=located_at], >> [name=product], [name=model],[name=productionYear], >> [name=productSerialNumber], [name=offerPrice]', 'target, target, target, >> target, target, target, target, target, target, target, target'); >> return false; >> }); >> </script> >> >> >> *CONTROLLER* >> def blackMarket(): >> form = SQLFORM(db.black_market2) >> if form.accepts(request, formname=None): >> return DIV("Message posted",_class="target", _style="color: >> white; border: solid 1px green; width: 160px; background-color: green; >> font-weight: bold; padding: 3px; border-radius:5px;") >> >> >> -- >> Resources: >> - http://web2py.com >> - http://web2py.com/book (Documentation) >> - http://github.com/web2py/web2py (Source code) >> - https://code.google.com/p/web2py/issues/list (Report Issues) >> --- >> You received this message because you are subscribed to the Google Groups >> "web2py-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to web...@googlegroups.com <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/web2py/d1607588-1a8c-48ca-963e-01060b218d89%40googlegroups.com >> >> <https://groups.google.com/d/msgid/web2py/d1607588-1a8c-48ca-963e-01060b218d89%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/cd71369b-319b-4e2a-a7a9-d9021b3d80dc%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.