Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The hide field options does not work. #129

Open
bob-pixeldeluxe opened this issue Mar 28, 2024 · 1 comment
Open

The hide field options does not work. #129

bob-pixeldeluxe opened this issue Mar 28, 2024 · 1 comment

Comments

@bob-pixeldeluxe
Copy link

Describe the bug

Im adding a custom link type for a formie form now I want to hide the link value field. It wil be a form popup.
Screenshot 2024-03-28 at 14 33 20
See the screenshot the checkbox right hidden is checked "verbergen"
But now it shows this:
Screenshot 2024-03-28 at 14 34 12
Looking with the inspector it does seem to be link value: name="fields[button][0][linkValue]"

Steps to reproduce

  1. Create a custom link type and hide the link value field

Craft CMS version

4.8.6

Plugin version

1.1.25

Multi-site?

Yes

Additional context

No response

@engram-design
Copy link
Member

You can't hide the linkValue field, that's the one required field you need to include. Whilst you can create a "custom" link type in this fashion, I'd recommend a proper element link type.

A quick example of this:

namespace modules\sitemodule;

use craft\events\RegisterComponentTypesEvent;
use modules\sitemodule\FormieLink;
use verbb\hyper\services\Links;
use yii\base\Event;

Event::on(Links::class, Links::EVENT_REGISTER_LINK_TYPES, function(RegisterComponentTypesEvent $event) {
    $event->types[] = FormieLink::class;
});
<?php
namespace modules\sitemodule;

use Craft;
use verbb\formie\elements\Form;
use verbb\hyper\base\ElementLink;
use verbb\hyper\fieldlayoutelements\LinkField;
use verbb\hyper\fields\HyperField;

class FormieLink extends ElementLink
{
    public static function elementType(): string
    {
        return Form::class;
    }

    public static function checkElementUri(): bool
    {
        return false;
    }

    public function getSettingsHtml(): ?string
    {
        $variables = $this->getSettingsHtmlVariables();

        return Craft::$app->getView()->renderTemplate("hyper/links/_element/settings", $variables);
    }
    
    public function getInputHtml(LinkField $layoutField, HyperField $field): ?string
    {
        $variables = $this->getInputHtmlVariables($layoutField, $field);

        return Craft::$app->getView()->renderTemplate("hyper/links/_element/input", $variables);
    }
}

That way, the linkValue field becomes an element select field for a Formie Form.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants