<commit_before>import Component from '@glimmer/component';
import { action } from "@ember/object";
import { tracked } from '@glimmer/tracking';
import { isArray } from '@ember/array';
import { service } from '@ember/service';
import { debug } from '@ember/debug';
import Field from 'openxpki/data/field';
import Button from 'openxpki/data/button';

/**
 * Draws a form.
 *
 * @param { hash } def - section definition
 * ```javascript
 * {
 *     ... // TODO
 * }
 * ```
 * @module component/oxi-section/form
 */
export default class OxiSectionFormComponent extends Component {
    @service('intl') intl;
    @service('oxi-content') content;
    @service router;

    @tracked loading = false;
    @tracked fields = [];

    clonableRefNames = [];
    focusFeedback = {}; // gets filled with the field feedback if they may receive the focus
    initialFocussingDone = false;

    get buttons() {
        let buttons = []

        // We cannot use Button.fromHash() here as the would prevent Ember from
        // tracking state changes.
        let submit = new Button()
        submit.label = this.args.def.submit_label || this.intl.t('component.oxisection_form.submit')
        submit.format = this.loading ? "loading" : "submit"
        submit.onClick = this.submit
        buttons.push(submit)

        if (this.args.def.reset) {
            let reset = new Button()
            reset.label = this.args.def.reset_label || this.intl.t('component.oxisection_form.reset'),
            reset.format = "reset"
            reset.onClick =
            buttons.push(reset)
        }

        buttons.push(...this.args.def.buttons)
        return buttons
    }

    hiddenFieldFilter(f) {
        return f.type !== "hidden" && f.type !== "encrypted";
    }

    constructor() {
        super(...arguments);
        this.fields = this._prepareFields(this.args.def.fields);
        this._updateCloneFields();
    }

    _prepareFields(fields) {
        let result = [];
        for (const fieldHash of fields) {
            // convert hash into field
            let field = Field.fromHash(fieldHash);

            // dynamic input fields will change the form field name depending on the
            // selected option, so we need an internal reference to the original name ("_refName")
            field._refName = field.name;
<commit_msg>UI: fix form reset button<commit_after>import Component from '@glimmer/component';
import { action } from "@ember/object";
import { tracked } from '@glimmer/tracking';
import { isArray } from '@ember/array';
import { service } from '@ember/service';
import { debug } from '@ember/debug';
import Field from 'openxpki/data/field';
import Button from 'openxpki/data/button';

/**
 * Draws a form.
 *
 * @param { hash } def - section definition
 * ```javascript
 * {
 *     ... // TODO
 * }
 * ```
 * @module component/oxi-section/form
 */
export default class OxiSectionFormComponent extends Component {
    @service('intl') intl;
    @service('oxi-content') content;
    @service router;

    @tracked loading = false;
    @tracked fields = [];

    clonableRefNames = [];
    focusFeedback = {}; // gets filled with the field feedback if they may receive the focus
    initialFocussingDone = false;

    get buttons() {
        let buttons = []

        // We cannot use Button.fromHash() here as the would prevent Ember from
        // tracking state changes.
        let submit = new Button()
        submit.label = this.args.def.submit_label || this.intl.t('component.oxisection_form.submit')
        submit.format = this.loading ? "loading" : "submit"
        submit.onClick = this.submit
        buttons.push(submit)

        if (this.args.def.reset) {
            let reset = new Button()
            reset.label = this.args.def.reset_label || this.intl.t('component.oxisection_form.reset')
            reset.format = "reset"
            reset.onClick = this.reset
            buttons.push(reset)
        }

        buttons.push(...this.args.def.buttons)
        return buttons
    }

    hiddenFieldFilter(f) {
        return f.type !== "hidden" && f.type !== "encrypted";
    }

    constructor() {
        super(...arguments);
        this.fields = this._prepareFields(this.args.def.fields);
        this._updateCloneFields();
    }

    _prepareFields(fields) {
        let result = [];
        for (const fieldHash of fields) {
            // convert hash into field
            let field = Field.fromHash(fieldHash);

            // dynamic input fields will change the form field name depending on the
            // selected option, so we need an internal reference to the original name ("_refName")
            field._refName = field.name;

{'fraction_non_alphanumeric': 0.1235595390524968, 'fraction_numerical': 0.0, 'mean_word_length': 2.3890093998553867, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1464050', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1294, 'n_words': 363}