0

my code:

from django.core.validators import RegexValidator
URL_VALIDATOR_MESSAGE = 'Not a valid URL'
URL_VALIDATOR = RegexValidator(regex='http\D+', message=URL_VALIDATOR_MESSAGE)

class SezPubBlock(blocks.StructBlock):
    sez = blocks.ListBlock(
      blocks.StructBlock(
        [
            ("title", blocks.CharBlock(classname="full title", icon="title", required=True)),
            ("url", blocks.URLBlock(required=True, validators=[URL_VALIDATOR])),
        ], label="Link", icon="link"
      ), label="Link sezione"
    )

link i need to insert: http://intranet/example/ the link is without dots and match regular expression 'http\D+' but when i save the page get the default error "Enter a valid URL."

if i add ".com" http://intranet.com/example/, works. i think the default validator is not overrided

nickb84
  • 591
  • 2
  • 6
  • 11

1 Answers1

1

i found a solution. i changed URLblock with CharBlock and it works

class SezPubBlock(blocks.StructBlock):

nome_sezione = blocks.CharBlock(required=True, verbose_name="My custom label")

sez = blocks.ListBlock(
    blocks.StructBlock(
        [
            ("title", blocks.CharBlock(classname="full title", icon="title", required=True)),
            ("url", blocks.CharBlock(required=True, validators=[URL_VALIDATOR], icon="link")),
        ], label="Link", icon="link"
    ), label="Link sezione"
)
nickb84
  • 591
  • 2
  • 6
  • 11
  • It would be great if you could paste in your code that you ended up using, this will help future Wagtail users solve similar problems. – LB Ben Johnston Nov 21 '21 at 09:15