Panel field validators not working in structure

Hi Kirby team,

I tried to validate fields within a structure like this:

title: Booking Manager
pages: false

fields:
	title:
		label: Title
		type: text
		required: true
	description:
		label: Description
		type: textarea
	
	products:
		label: Products
		type: structure
		entry: >
			<h1>{{ title }}</h1>
			<p><b>Description:</b> {{ description }}</p>
			<p><b>Price:</b> {{ price }}</p>
		fields:
			title:
				label: Title
				type: text
				required: true
			description:
				label: Description
				type: textarea
				required: true
			price:
				label: Price
				type: text
				validate:
					num
				help: Please type in a number

Validation works fine outside of the products structure (not included in this example but I tried it with “validate: num”), the price part is where I get problems. When entering and saving a text here, it does not give me an error message. When editing the just created structure though, I get an error message.
Shouldn’t there be an immediate error message when trying to enter a alpha text into a numerical validated field?

Cheers
Jan

PS: This is the same for every validation tried inside a structure field

Hm, for me it doesn’t work outside of a structure field either in the latest Kirby version while it does in an older one. You could just use a number field instead of a text field, where the validation is already built in.

The problem with a number field is that it doesn’t accept floating point numbers which I need…

It does, doesn’t it? You just have to enter them manually. It uses the num validator which checks if the input is numeric.

Nope for me it doesn’t… For example I trie entering 123.123 and a message appears “Please enter a valid value. The two nearest valid values are 123 and 124”

In my experience, blueprint validation rules have never worked inside a structure field.

Ok that’s too bad, maybe it will be fixed in the next version then…
The funny part is, that I get an error message when editing the structure right away (before saving the whole thing).
Thanks for the worries though!

Any news on this? Do validators in structure fields work now?

I just tested (Kirby/Panel 2.2.3) with a text field inside a structure field that validates using a regular expression (match) and by using the min and max values. It all works just fine for me and the rules prevent me from saving the structure item.

I’m marking this as solved. If anyone continues to have problems with validation, don’t hesitate to post here and I will reopen.

Great to hear :slight_smile: I didn’t updated yet …

tested in 2.3.2, seems not to work as expected:

    fields:
  category:
    label: Category
    type: select
    validate:
      minLength: 1
    default: architecture
    options:
      design: Design
      architecture: Architecture
      photography: Photography
      3d: 3D
      web: Web

there is no validation going on… no error if nothing is selected.

S.

Have you tried required: true? Validate does not seem to make much sense here.

According to https://getkirby.com/docs/cheatsheet/validators/min-length the syntax is correct or do i miss something?

S.

I’m not so sure that makes sense for a select field. Have you tested if it works outside of the structure field?

it should check if something is selected. if i select the first (empty) row it should give a error.

not tested yet outside of structure field… will do so.

S.

As Sonja wrote: That’s what the require option is for.

1 Like