Validator with Edge Component

Hi guys,

Could someone please assist with a pair of fresh eyes on this issue, I am using edge components to build my forms but when a field does meet the requirements set for the validator and returns, the other fields have been cleared.

Here is my code:

Route

Route.post('Components/Create', 'CreateComponentController.processComponentCreation').validator('CreatePageComponentValidator')

Input Field Component (Sorry I have some HTML markup in there as well)

<div class="form-group col-md-{{ input_col_size }} mb-{{ input_margin_bottom }}">
  <strong>
    <label for="{{ related_to }}">{{ input_label_text }}</label>
  </strong>

  <input
    type="{{ input_type ? input_type : 'text'}}"
    class="form-control"
    id="{{ input_name }}"
    name="{{ input_name }}"
    @if(input_value)
      value="{{ input_value ? input_value : old( input_name, '') }}"
    @else
      placeholder="{{ input_placeholder }}"
    @endif
    {{ required ? 'required' : null }}
    {{ disabled ? 'disabled' : null }}
    @if(input_placeholder)
      placeholder="{{ input_placeholder }}"
    @endif
  >
</div>

Component Definition within my edge files

@!component('components.input', {
  input_col_size: 12,
  input_margin_bottom: 4,
  type: 'text',
  input_name: 'component_name',
  input_placeholder: 'Provide a Memorable Component Name',
  related_to: 'component_name',
  input_label_text: 'Component Name *',
  input_value: '',
  required: false,
})
@if(hasErrorFor('component_name'))
<div class="error-info">
  <span>
    <img src="{{ assetsUrl('admin/assets/img/icon-info.svg') }}" class="icon" alt="">
    {{ getErrorFor('component_name') }}
  </span>
</div>
@endif

Any assistance will be appreciated.

Thanks

2 Likes

@McSneaky @virk Can you please provide any insights on this?

Thanks in advance

Hello!

Sorry for long delay, to be hones I haven’t ever used this feature, so I don’t know exact answer

But are you setting old value in session?
https://adonisjs.com/docs/4.1/sessions#_oldkey_defaultvalue

You need to set it to flash store first
https://adonisjs.com/docs/4.1/sessions#_flash_messages