We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45766
    • 78 Posts
    hm, seems that modx don't put the content from the fields not into the HTML-Code, like the extended fields.
    I am lost…
      • 3749
      • 24,544 Posts
      My apologies. I finally found time to test with a textarea and it's doing the same thing for me. I don't think TinyMCE is involved. It's not installed and the problem happens even when it's not a richtext field.

      So far, I have no clue what's causing it or why MODX is treating the field differently than the other textarea fields on the form, but I'm pretty sure it's not anything you're doing wrong.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 45766
        • 78 Posts
        Ok. That’s good for me, but bad for the job wink

        I have 2 workarounds in my mind:


        1. work with outputfilter :nl2br:replace=‚
          ==??‘ but I don’t know what to write instead of the ??. Ist there a character for newline?
        2. show the text as html and have an inactive textarea. If I would like to change the text I have to activate the textarea and copy the text into it. But dont know how to realize it. That it’s good for modx
          • 3749
          • 24,544 Posts
          In PHP, the character for newline is "\n" (must be double quotes).

          After a few hours of fiddling, I think the problem is in the MODX ExtJS code.

          The newlines are there in the DB as you said. They're also there when the data is pulled from the DB. They're even there after the call to $modx->getChunk(). So they're there in the page output when MODX renders it.

          I'm guessing somewhat, but the JS that renders the page in the Manager has the resource fields hard-coded into it. The textarea fields are specified with an xtype of 'textarea'. Because the ExtJS code that renders the page doesn't know that our field is a textarea (even though its HTML is exactly the same as that for the introtext and description fields), it uses the default xtype of text. I believe it strips out any newlines when rendering it. Short of using a custom class and some fancy JS code that somehow convinces ExtJS that these are fields with an xtype of textarea (and I'm not sure that's possible), I don't see any solution.

          I may be able to modify the plugin code to insert br tags with nl2br(), but it's not a great solution, and the lines would still appear on one line:

          line1<br />line2<br />line3


          I think the br tags would persist.

          Would that help?




            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 45766
            • 78 Posts
            First: Thanks for your very good support!

            But this would not be an solution, because we are running in trouble for the frontend editing which do right.

            So the user will see the br's and to explain them that this is an line break will be hard and uncomfortable for them to realize.

            Backend editing is just for admins, if an description has to be changed by them. Most the user edit his infos at the frontend.
            I think i would try to implement a short Script inside the chunk that acctivates a textarea if the admin clicks a buttin or fills it after loading with the content of a data-attribute.

            will report if it works and how i made it (hopefully wink )
              • 3749
              • 24,544 Posts
              I'm not sure this is helpful, but it might be worth trying TinyMCE.

              If you add "modx-richtext" as class of the textarea with TinyMCE (or much better, TinyMCEWrapper), it's possible that MODX would hand off the field to TinyMCE and not mess with the content. With TinyMCEWrapper, you can customize TinyMCE to be very minimal if you want to and also customize how it handles the content of the field.

              Another option would be NewsPublisher, which would let users edit the resource in the front end after logging in. TBH, I can't remember how well NewsPublisher works with extended resources (for sure it would work if this was a TV), but NP would manage the display rather than ExtJS and I'm confident that the newlines would be handled properly.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 45766
                • 78 Posts
                Hi,

                here is my workaround for that problem:

                Frontend Editing (user edit his own profile).
                Everything works as it should work. Using classExtender and Login.

                Backend
                I would like to have Textareas and not RhichText, because the admins should edit the content like the users without rhichText.


                1. Showing the content as html with output-filter :nl2br in a grey box
                2. Showing a disabled blank Textarea
                3. Making 2 Buttons which enable/disable the textarea

                If an admin would like to change the content he has to

                1. click edit (enable textarea)
                2. copy content from the grey box
                3. paste and edit it

                Here is an example
                (Because jQuery doesn't work that simple, with pure JavaScript
                <div class="x-form-item x-tab-item" tabindex="-1">
                	<label style="width:auto;" class="x-form-item-label">
                		EVZ Straße & Nr.
                	</label>
                	<div style="padding: 10px; background-color: #cdcdcd; margin: 5px 0px 10px 0px;">
                		[[+evzAddress:nl2br]]
                	</div>
                	
                	<span style="cursor: pointer; font-weight: bold; color: #3697cd;" onclick="document.getElementById('evzAddress').disabled = false; document.getElementById('evzAddress').style.borderColor ='#1fbf37';">Edit</span> // 
                	<span style="cursor: pointer; font-weight: bold; color: #3697cd;" onclick="document.getElementById('evzAddress').disabled = true; document.getElementById('evzAddress').style.borderColor ='red';">Cancel</span>
                	
                	<div class="x-form-element" style="padding-left:0;">
                		<textarea style="width: 716px; height: 48px;" autocomplete="off" name="evzAddress" class="modx-richtext x-form-textarea x-form-field" title="" id="evzAddress" disabled></textarea>
                	</div>
                	<div class="x-form-clear-left"></div>
                </div>
                
                  • 3749
                  • 24,544 Posts
                  I'm glad you found a worakaround. Sorry I couldn't come up with a better built-in solution.

                  I did have another thought:

                  You could create a textarea TV to duplicate the value and use a plugin attached to OnDocFormSave to write the TV value to the custom table. If necessary, it could also load the values into the TV from the custom table in the Manager in another part of the plugin connected to OnManagerPageBeforeRender. You would leave that field out of the TPL in the Manager and just edit the TV.

                  A simple utility snippet could run once to copy the values currently in the table to the modTemplateVarResource objects for each resource.

                  It's kind of ugly to have to go to the TV just to enter that field, so it's probably not a great solution, though you could create TVs for all the fields and handle all of them in the plugin (eliminating the ClassExtender plugin that displays the fields). That would give you the standard Manager editing and the searching and sorting capabilities of the custom table.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 45766
                    • 78 Posts
                    :D Thanks. Sounds … interesting wink

                    But this time i like my solution more. Works fine for the customer.