[Form] isChecked

Das Forum soll der Ablage von Lösungen für immer wieder auftauchende Problemstellungen dienen. // This forum contains solutions to problems that frequently occur.
Antworten
Coach83
Beiträge: 269
Registriert: 13.05.2010, 17:33:12
Kontaktdaten:

[Form] isChecked

Beitrag von Coach83 » 16.09.2014, 14:32:19

Hallo,

woran kann es denn liegen, dass eine Checkbox nicht richtig ausgewertet wird? Ansonsten werden alle Felder korrekt ausgelesen..?!

Code: Alles auswählen

$isFinishedField = $formAdd->getFormElementByName('isFinished');

if ($formAdd->isSent() && $formAdd->isValid()) 
      if ($isFinishedField->isChecked()) {
                $article->setisFinished(1);
            } else {
                $article->setisFinished(0);
            }
}

Benutzeravatar
dr.e.
Administrator
Beiträge: 4525
Registriert: 04.11.2007, 16:13:53

Re: [Form] isChecked

Beitrag von dr.e. » 17.09.2014, 09:38:09

Hallo Coach,

das kann unterschiedliche Gründe haben. Kannst du mal das zugehörige Formular posten? Wird die Checkbox dynamisch zum Formular hinzugefügt?
Viele Grüße,
Christian

dingsda
Beiträge: 49
Registriert: 03.02.2014, 04:00:36

Re: [Form] isChecked

Beitrag von dingsda » 17.09.2014, 10:36:17

Welche Version des Frameworks nutzt du?

Coach83
Beiträge: 269
Registriert: 13.05.2010, 17:33:12
Kontaktdaten:

Re: [Form] isChecked

Beitrag von Coach83 » 17.09.2014, 12:19:15

die Aktuelle

Lade das Formular mittels Ajax-Aufruf in die aktuelle Seite.

Das Versenden wird dann "normal" durchgeführt - das Formular dazu sieht so aus:

Code: Alles auswählen

<html:form name="ArticleAdd" id="ArticleAdd" class="form-horizontal">
    <link rel="stylesheet" type="text/css" href="css/codemirror/codemirror.min.css" />
    <link rel="stylesheet" href="css/codemirror/blackboard.min.css">
    <link rel="stylesheet" href="css/codemirror/monokai.min.css">
    <script type="text/javascript" src="/javascripts/codemirror/codemirror.js"></script>
    <script src="/javascripts/codemirror/xml.min.js"></script>
    <script src="/javascripts/codemirror/formatting.min.js"></script>
    <script>
        init.push(function() {
            if (!$('html').hasClass('ie8')) {
                $('#Text').summernote({height: 200, tabsize: 2, codemirror: {theme: 'monokai'}});
                $('#Intro').summernote({height: 200, tabsize: 2, codemirror: {theme: 'monokai'}});
            }
            $('#summernote-boxed').switcher({
                on_state_content: '<span class="fa fa-check" style="font-size:11px;"></span>',
                off_state_content: '<span class="fa fa-times" style="font-size:11px;"></span>'
            });
            $('#summernote-boxed').on($('html').hasClass('ie8') ? "propertychange" : "change", function() {
                var $panel = $(this).parents('.panel');
                if ($(this).is(':checked')) {
                    $panel.find('.panel-body').addClass('no-padding');
                    $panel.find('.panel-body > *').addClass('no-border');
                } else {
                    $panel.find('.panel-body').removeClass('no-padding');
                    $panel.find('.panel-body > *').removeClass('no-border');
                }
            });

            // Setup validation
            $("#ArticleAdd").validate({
                focusInvalid: true,
                rules: {
                    'Title': {
                        required: true,
                        minlength: 5
                    },
                    'SubTitle': {
                        required: true,
                        minlength: 5
                    },
                    'Article_Category': {
                        required: true
                    },
                    'KeywordList': {
                        required: true
                    },
                    'Intro': {
                        required: true,
                        minlength: 5
                    }
                },
                messages: {
                    'Title': '<html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.val.title" />',
                    'SubTitle': '<html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.val.subTitle" />',
                    'Article_Category': '<html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.val.category" />',
                    'KeywordList': '<html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.val.keywords" />',
                    'Intro': '<html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.val.intro" />'
                }
            });


        });
    </script>
    
    <div class="row">
        <div class="col-md-8">
            <div class="panel">
                <div class="panel-heading panel-danger panel-dark panel-body-colorful widget-profile widget-profile-centered">
                    <div class="widget-profile-header">
                        <span><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.settings" /> </span>
                    </div>
                </div> <!-- / .panel-heading -->
                <div class="panel-body">
                    <div class="row">
                        <div class="col-md-6 padding-sm">
                            <form:text name="Title" id="Title" class="col-md-12 form-control" placeholder="Titel" />
                        </div>
                        <div class="col-md-6 padding-sm">
                            <form:text name="SubTitle" id="SubTitle" class="col-md-12 form-control" placeholder="Untertitel" />
                        </div>
                    </div>                    

                    <div class="row">
                        <div class="col-md-6 form-group no-margin-hr">
                            <label class="control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.date" /></label>
                            <form:date name="Date" id="Date" maxlength="100" class="col-md-12" />
                        </div>
                        <div class="col-md-6 form-group no-margin-hr">
                            <label class="control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.time" /></label>
                            <form:time name="Time" id="Time" maxlength="100" class="col-md-12" />
                        </div>
                    </div>

                    <hr class="page-width">

                    <div class="row">
                        <div class="col-md-6 form-group no-margin-hr">
                            <label class="control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.category" /></label><br />
                            <form:select size="5" id="Article_Category" name="Article_Category" class="col-md-12 form-control" />
                        </div>
                        <div class="col-md-6 form-group no-margin-hr">
                            <label class="control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.keywords" /></label><br />
                            <form:area name="KeywordList" id="KeywordList" class="col-md-8 form-control" placeholder="Schlüsselworte" />
                        </div>
                    </div>

                    <hr class="page-width">

                    <div class="row">
                        <div class="col-md-6 form-group no-margin-hr">
                            <label class="control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.match" /></label>
                            <form:select name="isMatch" class="col-md-12 form-control" />
                        </div> 

                        <div class="col-md-6 form-group no-margin-hr">
                            <label class="control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.team" /></label>
                            <form:select name="TeamList" class="col-md-12 form-control" />
                        </div>
                        <div class="col-md-6 form-group no-margin-hr">
                            <label class="control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.team1" /></label>
                            <form:text name="Team1" class="col-md-12 form-control" />
                        </div> 

                        <div class="col-md-6 form-group no-margin-hr">
                            <label class="control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.team2" /></label>
                            <form:text name="Team2" class="col-md-12 form-control" />
                        </div>
                    </div>

                    <hr class="page-width">

                    <div class="row">
                        <div class="col-md-6 form-group no-margin-hr">
                            <label class="control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.result" /></label>
                            <form:text name="GoalsTeam1" style="width: 25px;" maxlength="2" /> : <form:text name="GoalsTeam2" style="width: 25px;" maxlength="2" />
                        </div>
                        <div class="col-md-6 form-group no-margin-hr">
                            <label class="control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.event" /></label>
                            <form:select name="Sonderereignis" class="col-md-12 form-control" />
                        </div>
                    </div>
                </div>
            </div>

            <div class="panel">
                <div class="panel-heading">
                    <span class="panel-title"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.introAndText" /> 
                        <a href="http://hackerwins.github.io/summernote/" target="_blank"><i class="fa fa-link"></i></a>
                    </span>
                </div>
                <div class="panel-body hidden-xs">
                    <p>
                    <html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.info" />
                    </p>
                    <ul>
                        <li><a target="_blank" href="http://www.heise.de/mac-and-i/downloads/65/1/1/6/7/1/0/3/Markdown-CheatSheet-Deutsch.pdf"><i class="fa fa-external-link"></i> Cheatsheet</a></li>
                        <li><a target="_blank" href="http://daringfireball.net/projects/markdown/syntax"><i class="fa fa-external-link"></i> Markdown Syntax </a></li>
                        <li><a target="_blank" href="http://michelf.ca/projects/php-markdown/extra/"><i class="fa fa-external-link"></i> Extra Syntax</a></li>
                    </ul>
                </div>
                <div class="panel-body col-md-12">                    
                    <form:area name="Intro" id="Intro" class="form-control" placeholder="Intro" />
                    <br /><hr class="page-width"><br />
                    <form:area name="Text" id="Text" class="form-control" placeholder="Text" />
                </div>
            </div>

        </div>

        <div class="col-md-4">
            <div class="panel panel-info panel-dark widget-profile">
                <div class="panel-heading">
                    <div class="widget-profile-bg-icon"><i class="fa fa-clock-o"></i></div>
                    <img class="widget-profile-avatar" alt='<html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="amgt" />' src='<stream:media class="widget-profile-avatar" namespace="APPLICATION\modules\article\pres\media" filename="social.jpg" />' />
                    <div class="widget-profile-header hidden-xs">
                        <span><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.timedPublish" /> </span><br />
                        <html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.timedPublishText" />                        
                    </div>
                </div> <!-- / .panel-heading -->
                <div class="panel-body">
                    <div class="row">
                        <div class="row form-group">
                            <label class="col-sm-4 control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.socialPublish" /></label>
                            <div class="col-sm-8">
                                <form:date name="PublishDate" yearrange="2014-2025" prepend-empty-options="true" /> 
                                <html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.socialPublishAt" />
                                <form:time name="PublishTime" hoursrange="0-24" showseconds="false" minutesinterval="30" />
                            </div>
                        </div>
                        <div class="row form-group">
                            <label class="col-sm-4 control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.facebook" /></label>
                            <div class="col-sm-8">
                                <form:checkbox name="publishOnFacebook" value="1" class="col-md-12 form-control" />
                                ${FacebookSchedule}
                                <form:marker name="FacebookReSchedule" />
                            </div>
                        </div>
                        <div class="row form-group">
                            <label class="col-sm-4 control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.twitter" /></label>
                            <div class="col-sm-8">
                                <form:checkbox name="publishOnTwitter" value="1" class="col-md-12 form-control" /> 
                                ${TwitterSchedule}
                                <form:marker name="TwitterReSchedule" />
                            </div>
                        </div>
                        <div class="row form-group">
                            <label class="col-sm-4 control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.google" /> </label>
                            <div class="col-sm-8">
                                <form:checkbox name="publishOnGoogle" value="1" class="col-md-12 form-control" />
                                ${GoogleSchedule}
                                <form:marker name="GoogleReSchedule" />
                            </div>
                        </div>

                        <p class="hidden-xs">
                        <html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.socialPublishText" />                            
                        </p>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="panel widget-messages-alt">
                <div class="panel-heading">
                    <span class="panel-title"><i class="panel-title-icon fa fa-magic"></i> <html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.otherSettings" /></span>
                </div> <!-- / .panel-heading -->
                <div class="panel-body padding-sm">
                    <div class="messages-list">

                        <div class="row form-group">
                            <label class="col-sm-4 control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.ended" /></label>
                            <div class="col-sm-8">
                                <form:checkbox name="isFinished" value="1" class="col-md-12 form-control" />
                            </div>
                        </div>

                        <div class="row form-group">
                            <label class="col-sm-4 control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.frontend" /></label>
                            <div class="col-sm-8">
                                <form:checkbox name="Visibility" value="1" class="col-md-12 form-control" />
                            </div>
                        </div>

                        <div class="row form-group">
                            <label class="col-sm-4 control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.topArticle" /></label>
                            <div class="col-sm-8">
                                <form:checkbox name="isTopArticle" value="1" class="col-md-12 form-control" />
                            </div>
                        </div>

                        <div class="row form-group">
                            <label class="col-sm-4 control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.autor" /></label>
                            <div class="col-sm-8">
                                <form:select name="autorList" id="autorList" class="col-md-12 form-control" />
                            </div>
                        </div>

                        <div class="row form-group">
                            <label class="col-sm-4 control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.comments" /></label>
                            <div class="col-sm-8">
                                <form:checkbox name="CommentsAllowed" value="1" class="col-md-12 form-control" />
                            </div>
                        </div>

                        <div class="row form-group">
                            <label class="col-sm-4 control-label"><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.slider" /></label>
                            <div class="col-sm-8">
                                <form:checkbox name="DisplayInSlider" value="1" class="col-md-12 form-control" />
                            </div>
                        </div>
                    </div>
                </div> <!-- / .panel-body -->
            </div>

            <div class="panel widget-messages-alt">
                <div class="panel-heading">
                    <span class="panel-title"><i class="panel-title-icon fa fa-files-o"></i><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="assignedArticles" /></span>
                </div> <!-- / .panel-heading -->
                <div class="panel-body padding-sm">
                    <div class="messages-list">
                        <form:multiselect name="linkedArticles" size="25" class="col-md-12 form-control" />
                    </div>
                </div> <!-- / .panel-body -->
            </div>
        </div>
    </div>

    <div class="row">
        <div class="panel widget-messages-alt">
            <div class="panel-heading">
                <span class="panel-title"><i class="panel-title-icon fa fa-files-o"></i><html:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="assignedMedia" /></span>
            </div> <!-- / .panel-heading -->
            <div class="panel-body padding-sm">
                <div class="messages-list">
                    ${MediaList}
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-4 pull-right">
            <div class="stat-panel">
                <form:hidden name="ArticleId" />
                <form:button name="ArticleButton" class="stat-cell bg-info valign-middle col-md-12">
                    <button:getstring namespace="APPLICATION\sites\pres" config="amgt-labels.ini" entry="addArticle.button" />
                </form:button>
            </div>
        </div>
    </div>

</html:form>
Mein Controller hat dann zB für eine Checkbox:

Code: Alles auswählen

$isFinishedField = $formAdd->getFormElementByName('isFinished');

if ($isFinishedField->isChecked()) {
                $article->setisFinished(1);
            } else {
                $article->setisFinished(0);
            }

dingsda
Beiträge: 49
Registriert: 03.02.2014, 04:00:36

Re: [Form] isChecked

Beitrag von dingsda » 17.09.2014, 12:44:53

Versuch mal in tools / form / taglib / CheckBoxTag.php die Methode onparsetime so zu ändern:

Code: Alles auswählen

   public function onParseTime() {

      $name = $this->getAttribute('name');
      $form = & $this->getParentObject();
      /* @var $form HtmlFormTag */
 
         if (isset($_REQUEST[$name])) {
            $this->check();
         } else {
            // Bug 626: in case the control has been checked by the so-called attribute,
            // we must un-check the control to avoid permanent checked boxes
            $this->uncheck();
         }
      

      // preset the content of the field
      $this->presetValue();
}
Edit:
Konkret ist hier die Prüfung weggefallen, ob das Formular gesendet wurde. Ich denke im apf-3.0 darf diese Prüfung nicht mehr hier stattfinden, weil der Button-Tag noch nicht geparsed wurde

Coach83
Beiträge: 269
Registriert: 13.05.2010, 17:33:12
Kontaktdaten:

Re: [Form] isChecked

Beitrag von Coach83 » 17.09.2014, 14:07:32

Super - daran lags.

Das $form = & $this->getParentObject(); wird dann aber doch an dieser Stelle auch nicht mehr benötigt, oder?

Benutzeravatar
dr.e.
Administrator
Beiträge: 4525
Registriert: 04.11.2007, 16:13:53

Re: [Form] isChecked

Beitrag von dr.e. » 18.09.2014, 22:51:52

Spannend. :) In meinen Tests mit dem APF 3.0 hat das bisher sauber funktionert. :roll:

@Coach: Darf ich dich bitten ein Issue im Tracker dafür zu eröffnen, ich schaue mir das mal genauer an.
Viele Grüße,
Christian

Antworten

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast