1

I have create one textarea in custom form.

And also set max_length from admin configuration for textarea ..

I want to add displayed massege "comment is too long" in template file.

<form autocomplete="off" data-mage-init='{"validation":{}}' data-hasrequired="<?php /* @escapeNotVerified */ echo __('comment is too long') ?>" action="<?php echo $this->getUrl("sales/ordercomment/index", ['order_id' => $orderId]); ?>" method="post" enctype="multipart/form-data" >
        <input name="form_key" type="hidden" value="<?php echo $block->getFormKey() ?>" />
        <section class="admin__page-section">
            <div class="admin__page-section-title">
                <span class="title"><?php /* @escapeNotVerified */ echo __('Order Comment') ?></span>
            </div>
            <div class="admin__page-section-content">
                <textarea  rows="3"
                           cols="50"
                           id="order-comment"
                           name="order"
                         maxlength="<?php echo $helper->getMaxLength();?>"
                          data-validate="{required:true}"
                           class="admin__control-textarea"> <?php echo nl2br($block->escapeHtml($comment)); ?></textarea>           
            </div> 
            <div class="admin__page-section-content">
                <button type="submit" class="btn btn-default">Submit</button>
            </div>
        </section>
    </form> 
  • Plz share your code which you have tried. – Rakesh Jesadiya Feb 10 '18 at 6:47
  • Updated my post – Mano M Feb 10 '18 at 6:51
  • are you want to set text comment is too long as placeholder in your textarea – Rakesh Jesadiya Feb 10 '18 at 6:53
  • yes ................ – Mano M Feb 10 '18 at 6:57
1

You have placed at wrong place your data-hasrequired attribute. you need to put with fieldset tag instead of form tag.

<form autocomplete="off" data-mage-init='{"validation":{}}' action="<?php echo $this->getUrl("sales/ordercomment/index", ['order_id' => $orderId]); ?>" method="post" enctype="multipart/form-data" >
  <fieldset class="fieldset comment" data-hasrequired="<?php /* @escapeNotVerified */ echo __('comment is too long') ?>">
        <input name="form_key" type="hidden" value="<?php echo $block->getFormKey() ?>" />
        <section class="admin__page-section">
            <div class="admin__page-section-title">
                <span class="title"><?php /* @escapeNotVerified */ echo __('Order Comment') ?></span>
            </div>
            <div class="admin__page-section-content">
                <textarea  rows="3"
                           cols="50"
                           id="order-comment"
                           name="order"
                         maxlength="<?php echo $helper->getMaxLength();?>"
                          data-validate="{required:true}"
                           class="admin__control-textarea"> <?php echo nl2br($block->escapeHtml($comment)); ?></textarea>           
            </div> 
            <div class="admin__page-section-content">
                <button type="submit" class="btn btn-default">Submit</button>
            </div>
        </section>
  </fieldset>
</form> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.